← Winnitude! Search  ·  Reader Mode (2333 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 9 LINKS

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, 2018

Environment

  • Pythonnet version: 2.3.0
  • Python version: 3.6-32
  • Operating System: Windows 10

Details

  • Getting a MethodBinding for a generic method results in the reference count being too high, so the tp_dealloc method on the MethodBinding never gets called, even when the MethodBinding goes 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions