Environment
- Pythonnet version: 3.01
- Python version: 3.7, 3.8, 3.9
- Operating System: Windows/Linux
- .NET Runtime: .NET Standard 2.0
Details
If I create a C# object in python directly from its constructor, the reference count on the python object is 1 too high.
test = TestClass()
print (f'test ref={sys.getrefcount(test)}')
will print 3 (it should be 2, since getrefcount itself takes a reference)
If, instead, I create a static function of TestClass, that just returns a new TestClass, all is well.
test = TestClass.Create()
print (f'test ref={sys.getrefcount(test)}')
will return 2
The consequence is that objects created by calling a constructor directly are never freed, so large memory leaks.
Environment
Details
If I create a C# object in python directly from its constructor, the reference count on the python object is 1 too high.
will print 3 (it should be 2, since getrefcount itself takes a reference)
If, instead, I create a static function of TestClass, that just returns a new TestClass, all is well.
will return 2
The consequence is that objects created by calling a constructor directly are never freed, so large memory leaks.