Memory Leak on MethodBinding for generic method · Issue #691 · pythonnet/pythonnet
Repository navigation
Memory Leak on MethodBinding for generic method #691
New issue
New issue
Closed
#2719
Closed
Memory Leak on MethodBinding for generic method #691 #2719
Description
@williamsardar's profile williamsardar opened on Jun 18, 2018Environment
- Pythonnet version: 2.3.0
- Python version: 3.6-32
- Operating System: Windows 10
Details
- Getting a
MethodBindingfor a generic method results in the reference count being too high, so thetp_deallocmethod on theMethodBindingnever gets called, even when theMethodBindinggoes out of scope.
namespace PlainOldNamespace
{
public class PlainOldClass
{
public void NonGenericMethod() { }
public void GenericMethod<T>() { }
}
}
import clr, sys
clr.AddReference("PlainOldAssembly")
from PlainOldNamespace import PlainOldClass
poc = PlainOldClass()
sys.getrefcount(poc.NonGenericMethod)
# 1
sys.getrefcount(poc.GenericMethod[clr.System.Double])
# 2 - should be 1
I think this could be down to a bug in MethodBinding.cs. This line looks suspicious. Why should the reference count get incremented here?
https://github.com/pythonnet/pythonnet/blob/master/src/runtime/methodbinding.cs#L59