Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

memory leak - simple function call in a loop #541

Closed
Labels
@den-run-ai

Description

@den-run-ai

I'm getting a memory leak with simple calls from .NET to Python function. The issue is reproducible on all pythonnet versions that I tested. When I test Python calls to .NET, then the memory leak is less obvious, since all resources are released when calling the CPythongc.collect(). Calling the same function from .NET does not release any resources, but calling the CLRGC.WaitForPendingFinalizers() blocks the execution.

memoryleakpykw.zip

>>>importclr>>>importSystem>>>foriinrange(20000000):...a=System.Double(i)...>>>importgc>>>gc.collect()

pyinclr.py

deftestmethod():return"abc"*3
usingSystem;usingPython.Runtime;namespacememoryleakpykw{classProgram{staticvoidMain(string[]args){PyObjectpymodule;PyObjectgc;PyObjecttestmethod;PythonEngine.Initialize();IntPtrpylock=PythonEngine.AcquireLock();{PyObjectsys=PythonEngine.ImportModule("sys");// Py.Import("sys");gc=PythonEngine.ImportModule("gc");// Py.Import("sys");sys.GetAttr("path").InvokeMethod("append",newPyString(@"C:\Users\denis.akhiyarov\source\repos\memoryleakpykw\pyinclr"));pymodule=PythonEngine.ImportModule("pyinclr");testmethod=pymodule.GetAttr("testmethod");}PythonEngine.ReleaseLock(pylock);Console.WriteLine("starting test for memory leak, press any key");Console.ReadKey();pylock=PythonEngine.AcquireLock();{for(inti=1;i<=1000000;i++){testmethod.Invoke();}}gc.InvokeMethod("collect");PythonEngine.ReleaseLock(pylock);GC.Collect();//GC.WaitForPendingFinalizers(); // this blocks executionGC.Collect();Console.WriteLine("finished test for memory leak, press any key");Console.ReadKey();}}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp