<div dir="ltr">Hi Eliana,<div><br></div><div>which version of pythonnet are you using? when you say you're using the latest are you building it yourself from the develop branch on github?</div><div><br></div><div>I had a quick look at the code that converts from a python object to a double, and I don't see any obvious memory leaks there. Perhaps the leak is the objects resulting from indexing into the tuple are never getting disposed? Try something like this instead and see if it helps (and report back as it may help improve the code if we know exactly what the problem is).</div><div><br>PyTuple myTuple = PyTuple.AsTuple(result);<div><br></div><div>double result0;<br>using (var item0 = myTuple[0])<br>    result0 = (double)item0.AsManagedObject(typeof(double));<br><br>double result1;<br>using (var item1 = myTuple[1])<br>    result1 = (double)item1.AsManagedObject(typeof(double));<br><br>myTuple.Dispose();<div><br></div><div>I would also use a using statement for the myTuple as well, just to be sure dispose is called in the case an exception is thrown somewhere.</div><div><br></div><div>Regards,</div><div>Tony</div></div></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Jan 15, 2016 at 8:06 PM Eliana Mendes <<a href="mailto:eliana.mendesp@gmail.com">eliana.mendesp@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif;background-image:initial;background-repeat:initial">Hello
experts,</span><span style="font-size:12pt;font-family:'Times New Roman',serif"></span></p>

<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> </span></p>

<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">I'm having a memory
leak problem when using the function AsManagedObject(typeof(double)).
Basically I have something like this: </span></p>

<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> </span></p>

<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">PyTuple myTuple =
PyTuple.AsTuple(result);</span></p>

<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">double result0 =
(double)myTuple[0].AsManagedObject(typeof(double));</span></p>

<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">double result1 =
(double)myTuple[1].AsManagedObject(typeof(double));</span></p>

<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">myTuple.Dispose();</span></p>

<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> </span></p>

<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">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.</span></p>

<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">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.</span></p>

<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"> </span></p>

<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">Thank you!</span></p><p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif"><br></span></p><p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">Eliana Mendes</span></p><p class="MsoNormal"><span style="font-size:12pt;font-family:Arial,sans-serif">Software Engineer</span></p><div><br></div></div>
_________________________________________________<br>
Python.NET mailing list - <a href="mailto:PythonDotNet@python.org" target="_blank">PythonDotNet@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/pythondotnet" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/pythondotnet</a></blockquote></div>