[Python.NET] Memory leak problem in function "AsManagedObject"

Eliana Mendes eliana.mendesp at gmail.com
Fri Jan 15 15:06:10 EST 2016

Hello experts,

I'm having a memory leak problem when using the
function AsManagedObject(typeof(double)). Basically I have something like

PyTuple myTuple = PyTuple.AsTuple(result);

double result0 = (double)myTuple[0].AsManagedObject(typeof(double));

double result1 = (double)myTuple[1].AsManagedObject(typeof(double));


where "result" is just a PyObject that returned from a python function. I
simplified the code above just so you can understand better, but the thing
is that the line that calls "AsManagedObject”  is executed thousands of
times and it is increasing significantly the memory heap (it goes over 3 GB
of memory in my scenario and it’s not released after execution). If I don't
call just this specific function the memory remains stable. But I don’t
know any other way to convert the PyObject to "double" unless using the
“AsManagedObject” function.

It sounds to me that some objects are allocated inside the
"AsManagedObject" method and they are not being released. Maybe it’s a bug
there. Any ideas? I'm using latest version of python for .NET.

Thank you!

Eliana Mendes

Software Engineer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20160115/8cff57e9/attachment.html>

More information about the PythonDotNet mailing list