From eliana.mendesp at gmail.com Fri Jan 15 15:06:10 2016 From: eliana.mendesp at gmail.com (Eliana Mendes) Date: Fri, 15 Jan 2016 14:06:10 -0600 Subject: [Python.NET] Memory leak problem in function "AsManagedObject" Message-ID: Hello experts, I'm having a memory leak problem when using the function AsManagedObject(typeof(double)). Basically I have something like this: PyTuple myTuple = PyTuple.AsTuple(result); double result0 = (double)myTuple[0].AsManagedObject(typeof(double)); double result1 = (double)myTuple[1].AsManagedObject(typeof(double)); myTuple.Dispose(); 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: From tony at pyxll.com Sun Jan 17 07:05:29 2016 From: tony at pyxll.com (Tony Roberts) Date: Sun, 17 Jan 2016 12:05:29 +0000 Subject: [Python.NET] Memory leak problem in function "AsManagedObject" In-Reply-To: References: Message-ID: Hi Eliana, 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? 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). PyTuple myTuple = PyTuple.AsTuple(result); double result0; using (var item0 = myTuple[0]) result0 = (double)item0.AsManagedObject(typeof(double)); double result1; using (var item1 = myTuple[1]) result1 = (double)item1.AsManagedObject(typeof(double)); myTuple.Dispose(); 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. Regards, Tony On Fri, Jan 15, 2016 at 8:06 PM Eliana Mendes wrote: > Hello experts, > > > > I'm having a memory leak problem when using the > function AsManagedObject(typeof(double)). Basically I have something like > this: > > > > PyTuple myTuple = PyTuple.AsTuple(result); > > double result0 = (double)myTuple[0].AsManagedObject(typeof(double)); > > double result1 = (double)myTuple[1].AsManagedObject(typeof(double)); > > myTuple.Dispose(); > > > > 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 > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: From eliana.mendesp at gmail.com Mon Jan 18 14:11:26 2016 From: eliana.mendesp at gmail.com (Eliana Mendes) Date: Mon, 18 Jan 2016 13:11:26 -0600 Subject: [Python.NET] Memory leak problem in function "AsManagedObject" In-Reply-To: References: Message-ID: Hello Tony, Thanks a lot for your answer! I actually just got directly the ?Python.Runtime.dll? from the download link in sourceforge: http://sourceforge.net/projects/pythonnet/files/. But from the description I see that the last update of that one was done in 2013. Would there be a newer version somewhere else that I could get? Perhaps this version I?m using is out of date and you have a newer one. Let me know if that?s the case. I tried your suggestion of putting the ?using? statement for the tuple objects, and also for ?myTuple?, and the memory is still increasing a lot. I?ve made a memory profile to see which objects are being retained and after I ran that statement 5 thousand times I got this: [image: Imagem inline 1] As you can see more that 12 thousand instances of ?PyInt? and more than 6 thousand of ?PyObject? are created . Apparently it is creating these ?PyInt? and ?PyObjects? somewhere inside the ?AsManagedObject?, because I don?t have PyInt objects anywhere in my code and this just happens when I call ?AsManagedObject?. Let me know if there is a newer version that could probably have that problem fixed which I am not aware of. I appreciate a lot your help! Best regards, Eliana 2016-01-17 6:05 GMT-06:00 Tony Roberts : > Hi Eliana, > > 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? > > 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). > > PyTuple myTuple = PyTuple.AsTuple(result); > > double result0; > using (var item0 = myTuple[0]) > result0 = (double)item0.AsManagedObject(typeof(double)); > > double result1; > using (var item1 = myTuple[1]) > result1 = (double)item1.AsManagedObject(typeof(double)); > > myTuple.Dispose(); > > 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. > > Regards, > Tony > > > On Fri, Jan 15, 2016 at 8:06 PM Eliana Mendes > wrote: > >> Hello experts, >> >> >> >> I'm having a memory leak problem when using the >> function AsManagedObject(typeof(double)). Basically I have something like >> this: >> >> >> >> PyTuple myTuple = PyTuple.AsTuple(result); >> >> double result0 = (double)myTuple[0].AsManagedObject(typeof(double)); >> >> double result1 = (double)myTuple[1].AsManagedObject(typeof(double)); >> >> myTuple.Dispose(); >> >> >> >> 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 >> >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> https://mail.python.org/mailman/listinfo/pythondotnet > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image.png Type: image/png Size: 70883 bytes Desc: not available URL: From denis.akhiyarov at gmail.com Mon Jan 18 17:54:42 2016 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Mon, 18 Jan 2016 22:54:42 +0000 Subject: [Python.NET] Memory leak problem in function "AsManagedObject" In-Reply-To: References: Message-ID: Your binaries are rather outdated.. Here is the latest branch: https://github.com/pythonnet/pythonnet/tree/develop And binaries here: https://pypi.python.org/pypi/pythonnet/2.1.0.dev1 http://www.lfd.uci.edu/~gohlke/pythonlibs/#pythonnet On Mon, Jan 18, 2016, 4:47 PM Eliana Mendes wrote: > Hello Tony, > > > > Thanks a lot for your answer! I actually just got directly the > ?Python.Runtime.dll? from the download link in sourceforge: > http://sourceforge.net/projects/pythonnet/files/. But from the > description I see that the last update of that one was done in 2013. Would > there be a newer version somewhere else that I could get? Perhaps this > version I?m using is out of date and you have a newer one. Let me know if > that?s the case. > > > > I tried your suggestion of putting the ?using? statement for the tuple > objects, and also for ?myTuple?, and the memory is still increasing a lot. > I?ve made a memory profile to see which objects are being retained and > after I ran that statement 5 thousand times I got this: > > > [image: Imagem inline 1] > > > As you can see more that 12 thousand instances of ?PyInt? and more than 6 > thousand of ?PyObject? are created . Apparently it is creating these > ?PyInt? and ?PyObjects? somewhere inside the ?AsManagedObject?, because I > don?t have PyInt objects anywhere in my code and this just happens when I > call ?AsManagedObject?. > > > > Let me know if there is a newer version that could probably have that > problem fixed which I am not aware of. > > > I appreciate a lot your help! > > > > Best regards, > > Eliana > > 2016-01-17 6:05 GMT-06:00 Tony Roberts : > >> Hi Eliana, >> >> 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? >> >> 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). >> >> PyTuple myTuple = PyTuple.AsTuple(result); >> >> double result0; >> using (var item0 = myTuple[0]) >> result0 = (double)item0.AsManagedObject(typeof(double)); >> >> double result1; >> using (var item1 = myTuple[1]) >> result1 = (double)item1.AsManagedObject(typeof(double)); >> >> myTuple.Dispose(); >> >> 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. >> >> Regards, >> Tony >> >> >> On Fri, Jan 15, 2016 at 8:06 PM Eliana Mendes >> wrote: >> >>> Hello experts, >>> >>> >>> >>> I'm having a memory leak problem when using the >>> function AsManagedObject(typeof(double)). Basically I have something like >>> this: >>> >>> >>> >>> PyTuple myTuple = PyTuple.AsTuple(result); >>> >>> double result0 = (double)myTuple[0].AsManagedObject(typeof(double)); >>> >>> double result1 = (double)myTuple[1].AsManagedObject(typeof(double)); >>> >>> myTuple.Dispose(); >>> >>> >>> >>> 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 >>> >>> _________________________________________________ >>> Python.NET mailing list - PythonDotNet at python.org >>> https://mail.python.org/mailman/listinfo/pythondotnet >> >> >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> https://mail.python.org/mailman/listinfo/pythondotnet >> > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image.png Type: image/png Size: 70883 bytes Desc: not available URL: From tony at pyxll.com Tue Jan 19 03:09:37 2016 From: tony at pyxll.com (Tony Roberts) Date: Tue, 19 Jan 2016 08:09:37 +0000 Subject: [Python.NET] Memory leak problem in function "AsManagedObject" In-Reply-To: References: Message-ID: Hi Eliana, it's best to build it yourself from github: https://github.com/pythonnet/pythonnet/tree/develop Failing that, you can get a recent build from pypi: https://pypi.python.org/pypi/pythonnet/2.1.0.dev1 The version source forge is pretty old and there have been a lot of fixes made since then. Regards, Tony On Mon, Jan 18, 2016 at 7:11 PM Eliana Mendes wrote: > Hello Tony, > > > > Thanks a lot for your answer! I actually just got directly the > ?Python.Runtime.dll? from the download link in sourceforge: > http://sourceforge.net/projects/pythonnet/files/. But from the > description I see that the last update of that one was done in 2013. Would > there be a newer version somewhere else that I could get? Perhaps this > version I?m using is out of date and you have a newer one. Let me know if > that?s the case. > > > > I tried your suggestion of putting the ?using? statement for the tuple > objects, and also for ?myTuple?, and the memory is still increasing a lot. > I?ve made a memory profile to see which objects are being retained and > after I ran that statement 5 thousand times I got this: > > > [image: image.png] > > > As you can see more that 12 thousand instances of ?PyInt? and more than 6 > thousand of ?PyObject? are created . Apparently it is creating these > ?PyInt? and ?PyObjects? somewhere inside the ?AsManagedObject?, because I > don?t have PyInt objects anywhere in my code and this just happens when I > call ?AsManagedObject?. > > > > Let me know if there is a newer version that could probably have that > problem fixed which I am not aware of. > > > I appreciate a lot your help! > > > > Best regards, > > Eliana > > 2016-01-17 6:05 GMT-06:00 Tony Roberts : > >> Hi Eliana, >> >> 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? >> >> 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). >> >> PyTuple myTuple = PyTuple.AsTuple(result); >> >> double result0; >> using (var item0 = myTuple[0]) >> result0 = (double)item0.AsManagedObject(typeof(double)); >> >> double result1; >> using (var item1 = myTuple[1]) >> result1 = (double)item1.AsManagedObject(typeof(double)); >> >> myTuple.Dispose(); >> >> 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. >> >> Regards, >> Tony >> >> >> On Fri, Jan 15, 2016 at 8:06 PM Eliana Mendes >> wrote: >> >>> Hello experts, >>> >>> >>> >>> I'm having a memory leak problem when using the >>> function AsManagedObject(typeof(double)). Basically I have something like >>> this: >>> >>> >>> >>> PyTuple myTuple = PyTuple.AsTuple(result); >>> >>> double result0 = (double)myTuple[0].AsManagedObject(typeof(double)); >>> >>> double result1 = (double)myTuple[1].AsManagedObject(typeof(double)); >>> >>> myTuple.Dispose(); >>> >>> >>> >>> 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 >>> >>> _________________________________________________ >>> Python.NET mailing list - PythonDotNet at python.org >>> https://mail.python.org/mailman/listinfo/pythondotnet >> >> >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> https://mail.python.org/mailman/listinfo/pythondotnet >> > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image.png Type: image/png Size: 70883 bytes Desc: not available URL: From eliana.mendesp at gmail.com Tue Jan 19 15:46:59 2016 From: eliana.mendesp at gmail.com (Eliana Mendes) Date: Tue, 19 Jan 2016 14:46:59 -0600 Subject: [Python.NET] Memory leak problem in function "AsManagedObject" In-Reply-To: References: Message-ID: Thank you all for the answers! I got the source code from the githup and built it myself, as you suggested. Unfortunately the memory leak problem remains even with this latest branch. But this time I was able to figure out where the problem is! The problem is not inside the ?AsMangedObject?? as I thought before, but instead it is inside the ?GetItem(int index)? method which is inside the " *pyobject*" class. This method creates a new instance of *PyInt *and a new instance of *PyObject*. Those are exactly the objects that my memory profiler was showing. In order to fix my problem I had to first edit this method to be like this: public virtual PyObject GetItem(int index) { PyInt key = new PyInt(index); PyObject item = GetItem((PyObject)key); key.Dispose(); return item; } After doing that, in my code, I had to add a dispose for myTuple[i]. So I changed my code to look something similar to this: PyObject tupleResult = myTuple[0]; results[0] = (double)tupleResult.AsManagedObject(typeof(double)); tupleResult.Dispose(); By doing those changes the problem was entirely fixed! I?m not sure who to contact exactly about changing the source code, but I would highly recommend in making those changes in the ?GetItem? method in order to avoid someone else having the same memory problem. Thanks a lot for all your help! Best regards, Eliana 2016-01-18 16:54 GMT-06:00 Denis Akhiyarov : > Your binaries are rather outdated.. > > Here is the latest branch: > > https://github.com/pythonnet/pythonnet/tree/develop > > And binaries here: > > https://pypi.python.org/pypi/pythonnet/2.1.0.dev1 > > http://www.lfd.uci.edu/~gohlke/pythonlibs/#pythonnet > > On Mon, Jan 18, 2016, 4:47 PM Eliana Mendes > wrote: > >> Hello Tony, >> >> >> >> Thanks a lot for your answer! I actually just got directly the >> ?Python.Runtime.dll? from the download link in sourceforge: >> http://sourceforge.net/projects/pythonnet/files/. But from the >> description I see that the last update of that one was done in 2013. Would >> there be a newer version somewhere else that I could get? Perhaps this >> version I?m using is out of date and you have a newer one. Let me know if >> that?s the case. >> >> >> >> I tried your suggestion of putting the ?using? statement for the tuple >> objects, and also for ?myTuple?, and the memory is still increasing a lot. >> I?ve made a memory profile to see which objects are being retained and >> after I ran that statement 5 thousand times I got this: >> >> >> [image: Imagem inline 1] >> >> >> As you can see more that 12 thousand instances of ?PyInt? and more than 6 >> thousand of ?PyObject? are created . Apparently it is creating these >> ?PyInt? and ?PyObjects? somewhere inside the ?AsManagedObject?, because I >> don?t have PyInt objects anywhere in my code and this just happens when I >> call ?AsManagedObject?. >> >> >> >> Let me know if there is a newer version that could probably have that >> problem fixed which I am not aware of. >> >> >> I appreciate a lot your help! >> >> >> >> Best regards, >> >> Eliana >> >> 2016-01-17 6:05 GMT-06:00 Tony Roberts : >> >>> Hi Eliana, >>> >>> 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? >>> >>> 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). >>> >>> PyTuple myTuple = PyTuple.AsTuple(result); >>> >>> double result0; >>> using (var item0 = myTuple[0]) >>> result0 = (double)item0.AsManagedObject(typeof(double)); >>> >>> double result1; >>> using (var item1 = myTuple[1]) >>> result1 = (double)item1.AsManagedObject(typeof(double)); >>> >>> myTuple.Dispose(); >>> >>> 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. >>> >>> Regards, >>> Tony >>> >>> >>> On Fri, Jan 15, 2016 at 8:06 PM Eliana Mendes >>> wrote: >>> >>>> Hello experts, >>>> >>>> >>>> >>>> I'm having a memory leak problem when using the >>>> function AsManagedObject(typeof(double)). Basically I have something like >>>> this: >>>> >>>> >>>> >>>> PyTuple myTuple = PyTuple.AsTuple(result); >>>> >>>> double result0 = (double)myTuple[0].AsManagedObject(typeof(double)); >>>> >>>> double result1 = (double)myTuple[1].AsManagedObject(typeof(double)); >>>> >>>> myTuple.Dispose(); >>>> >>>> >>>> >>>> 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 >>>> >>>> _________________________________________________ >>>> Python.NET mailing list - PythonDotNet at python.org >>>> https://mail.python.org/mailman/listinfo/pythondotnet >>> >>> >>> _________________________________________________ >>> Python.NET mailing list - PythonDotNet at python.org >>> https://mail.python.org/mailman/listinfo/pythondotnet >>> >> >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> https://mail.python.org/mailman/listinfo/pythondotnet > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image.png Type: image/png Size: 70883 bytes Desc: not available URL: From tony at pyxll.com Wed Jan 20 03:53:14 2016 From: tony at pyxll.com (Tony Roberts) Date: Wed, 20 Jan 2016 08:53:14 +0000 Subject: [Python.NET] Memory leak problem in function "AsManagedObject" In-Reply-To: References: Message-ID: Hi Eliana, great, glad you were able to find the problem. I'll make that change in github. thanks, Tony On Tue, Jan 19, 2016 at 8:46 PM Eliana Mendes wrote: > Thank you all for the answers! > > > I got the source code from the githup and built it myself, as you > suggested. Unfortunately the memory leak problem remains even with this > latest branch. But this time I was able to figure out where the problem is! > > > > The problem is not inside the ?AsMangedObject?? as I thought before, but > instead it is inside the ?GetItem(int index)? method which is inside the " > *pyobject*" class. This method creates a new instance of *PyInt *and a > new instance of *PyObject*. Those are exactly the objects that my memory > profiler was showing. In order to fix my problem I had to first edit this > method to be like this: > > > public virtual PyObject GetItem(int index) { > > PyInt key = new PyInt(index); > > PyObject item = GetItem((PyObject)key); > > key.Dispose(); > > return item; > > } > > > > After doing that, in my code, I had to add a dispose for myTuple[i]. So I > changed my code to look something similar to this: > > > > PyObject tupleResult = myTuple[0]; > > results[0] = > (double)tupleResult.AsManagedObject(typeof(double)); > > tupleResult.Dispose(); > > > > By doing those changes the problem was entirely fixed! > > > > I?m not sure who to contact exactly about changing the source code, but I > would highly recommend in making those changes in the ?GetItem? method in > order to avoid someone else having the same memory problem. > > > > Thanks a lot for all your help! > > > Best regards, > > > Eliana > > 2016-01-18 16:54 GMT-06:00 Denis Akhiyarov : > >> Your binaries are rather outdated.. >> >> Here is the latest branch: >> >> https://github.com/pythonnet/pythonnet/tree/develop >> >> And binaries here: >> >> https://pypi.python.org/pypi/pythonnet/2.1.0.dev1 >> >> http://www.lfd.uci.edu/~gohlke/pythonlibs/#pythonnet >> >> On Mon, Jan 18, 2016, 4:47 PM Eliana Mendes >> wrote: >> >>> Hello Tony, >>> >>> >>> >>> Thanks a lot for your answer! I actually just got directly the >>> ?Python.Runtime.dll? from the download link in sourceforge: >>> http://sourceforge.net/projects/pythonnet/files/. But from the >>> description I see that the last update of that one was done in 2013. Would >>> there be a newer version somewhere else that I could get? Perhaps this >>> version I?m using is out of date and you have a newer one. Let me know if >>> that?s the case. >>> >>> >>> >>> I tried your suggestion of putting the ?using? statement for the tuple >>> objects, and also for ?myTuple?, and the memory is still increasing a lot. >>> I?ve made a memory profile to see which objects are being retained and >>> after I ran that statement 5 thousand times I got this: >>> >>> >>> [image: Imagem inline 1] >>> >>> >>> As you can see more that 12 thousand instances of ?PyInt? and more than >>> 6 thousand of ?PyObject? are created . Apparently it is creating these >>> ?PyInt? and ?PyObjects? somewhere inside the ?AsManagedObject?, because I >>> don?t have PyInt objects anywhere in my code and this just happens when I >>> call ?AsManagedObject?. >>> >>> >>> >>> Let me know if there is a newer version that could probably have that >>> problem fixed which I am not aware of. >>> >>> >>> I appreciate a lot your help! >>> >>> >>> >>> Best regards, >>> >>> Eliana >>> >>> 2016-01-17 6:05 GMT-06:00 Tony Roberts : >>> >>>> Hi Eliana, >>>> >>>> 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? >>>> >>>> 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). >>>> >>>> PyTuple myTuple = PyTuple.AsTuple(result); >>>> >>>> double result0; >>>> using (var item0 = myTuple[0]) >>>> result0 = (double)item0.AsManagedObject(typeof(double)); >>>> >>>> double result1; >>>> using (var item1 = myTuple[1]) >>>> result1 = (double)item1.AsManagedObject(typeof(double)); >>>> >>>> myTuple.Dispose(); >>>> >>>> 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. >>>> >>>> Regards, >>>> Tony >>>> >>>> >>>> On Fri, Jan 15, 2016 at 8:06 PM Eliana Mendes >>>> wrote: >>>> >>>>> Hello experts, >>>>> >>>>> >>>>> >>>>> I'm having a memory leak problem when using the >>>>> function AsManagedObject(typeof(double)). Basically I have something like >>>>> this: >>>>> >>>>> >>>>> >>>>> PyTuple myTuple = PyTuple.AsTuple(result); >>>>> >>>>> double result0 = (double)myTuple[0].AsManagedObject(typeof(double)); >>>>> >>>>> double result1 = (double)myTuple[1].AsManagedObject(typeof(double)); >>>>> >>>>> myTuple.Dispose(); >>>>> >>>>> >>>>> >>>>> 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 >>>>> >>>>> _________________________________________________ >>>>> Python.NET mailing list - PythonDotNet at python.org >>>>> https://mail.python.org/mailman/listinfo/pythondotnet >>>> >>>> >>>> _________________________________________________ >>>> Python.NET mailing list - PythonDotNet at python.org >>>> https://mail.python.org/mailman/listinfo/pythondotnet >>>> >>> >>> _________________________________________________ >>> Python.NET mailing list - PythonDotNet at python.org >>> https://mail.python.org/mailman/listinfo/pythondotnet >> >> >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> https://mail.python.org/mailman/listinfo/pythondotnet >> > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image.png Type: image/png Size: 70883 bytes Desc: not available URL: From Kresimir.Simunic at Reicofil.com Wed Jan 27 08:22:26 2016 From: Kresimir.Simunic at Reicofil.com (Simunic,Kresimir) Date: Wed, 27 Jan 2016 13:22:26 +0000 Subject: [Python.NET] Versions support Message-ID: <140586760BB9EB4B915EB258E3CFB7C0FC95003A@VM-SERVER76.local.reifenhauser.com> Hi there, Can someone tell me if Python.Net supports some newer Versions of Python (as 3.3) ? The only Python.Runtime DLL I could find was for 2.7 Version. Thanks Regards -- Kre?imir ?imuni? Automatisierung Reifenh?user Reicofil GmbH & Co. KG Spicher Stra?e 46, 53844 Troisdorf, Germany Registergericht Siegburg, Reg.Nr. HR A 4534 USt-IdNr. DE 814359351, Steuer-Nr. 5220/5760/0426 Reifenh?user Reicofil Verwaltungs-GmbH Registergericht Siegburg, Reg.Nr. HR B 788 Gesch?ftsf?hrer: Dr.-Ing. Bernd Kunze Please note: This message may contain information which is privileged, confidential and proprietary. -------------- next part -------------- An HTML attachment was scrubbed... URL: From OysteinIdema.Torget at statkraft.com Wed Jan 27 10:31:52 2016 From: OysteinIdema.Torget at statkraft.com (=?windows-1257?Q?Torget_=A8ystein_Idema?=) Date: Wed, 27 Jan 2016 15:31:52 +0000 Subject: [Python.NET] Versions support In-Reply-To: <140586760BB9EB4B915EB258E3CFB7C0FC95003A@VM-SERVER76.local.reifenhauser.com> References: <140586760BB9EB4B915EB258E3CFB7C0FC95003A@VM-SERVER76.local.reifenhauser.com> Message-ID: The dev1 build works for Python 3.3 and 3.4 https://pypi.python.org/pypi/pythonnet/2.1.0.dev1 We use it in production systems and haven?t experienced any significant problems with it related to Anaconda Python 3.4.3. Cheers, ?ystein From: PythonDotNet [mailto:pythondotnet-bounces+oysteinidema.torget=statkraft.com at python.org] On Behalf Of Simunic,Kresimir Sent: 27. januar 2016 14:22 To: pythondotnet at python.org Subject: [Python.NET] Versions support Hi there, Can someone tell me if Python.Net supports some newer Versions of Python (as 3.3) ? The only Python.Runtime DLL I could find was for 2.7 Version. Thanks Regards -- Kre?imir ?imuni? Automatisierung Reifenh?user Reicofil GmbH & Co. KG Spicher Stra?e 46, 53844 Troisdorf, Germany Registergericht Siegburg, Reg.Nr. HR A 4534 USt-IdNr. DE 814359351, Steuer-Nr. 5220/5760/0426 Reifenh?user Reicofil Verwaltungs-GmbH Registergericht Siegburg, Reg.Nr. HR B 788 Gesch?ftsf?hrer: Dr.-Ing. Bernd Kunze Please note: This message may contain information which is privileged, confidential and proprietary. -------------- next part -------------- An HTML attachment was scrubbed... URL: From denis.akhiyarov at gmail.com Wed Jan 27 11:30:39 2016 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Wed, 27 Jan 2016 10:30:39 -0600 Subject: [Python.NET] Versions support In-Reply-To: References: <140586760BB9EB4B915EB258E3CFB7C0FC95003A@VM-SERVER76.local.reifenhauser.com> Message-ID: there is also python 3.5 branch, but I have not tested it yet: https://github.com/sdpython/pythonnet3 On Wed, Jan 27, 2016 at 9:31 AM, Torget ?ystein Idema < OysteinIdema.Torget at statkraft.com> wrote: > The dev1 build works for Python 3.3 and 3.4 > > > > https://pypi.python.org/pypi/pythonnet/2.1.0.dev1 > > > > We use it in production systems and haven?t experienced any significant > problems with it related to Anaconda Python 3.4.3. > > > > Cheers, > > ?ystein > > > > *From:* PythonDotNet [mailto:pythondotnet-bounces+oysteinidema.torget= > statkraft.com at python.org] *On Behalf Of *Simunic,Kresimir > *Sent:* 27. januar 2016 14:22 > *To:* pythondotnet at python.org > *Subject:* [Python.NET] Versions support > > > > > > Hi there, > > > > Can someone tell me if Python.Net supports some newer Versions of Python > (as 3.3) ? > > > > The only Python.Runtime DLL I could find was for 2.7 Version. > > > > Thanks > > > > Regards > > > > -- > > *Kre?imir ?imuni**?* > Automatisierung > > > > > > > *Reifenh?user Reicofil GmbH & Co. KG* > Spicher Stra?e 46, 53844 Troisdorf, Germany > Registergericht Siegburg, Reg.Nr. HR A 4534 > USt-IdNr. DE 814359351, Steuer-Nr. 5220/5760/0426 > Reifenh?user Reicofil Verwaltungs-GmbH > Registergericht Siegburg, Reg.Nr. HR B 788 > Gesch?ftsf?hrer: Dr.-Ing. Bernd Kunze > > Please note: This message may contain information which is privileged, > confidential and proprietary. > > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet > -------------- next part -------------- An HTML attachment was scrubbed... URL: From denis.akhiyarov at gmail.com Fri Jan 29 01:52:23 2016 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Fri, 29 Jan 2016 00:52:23 -0600 Subject: [Python.NET] pythonnet 2.0.0 released In-Reply-To: <60CDCA83B420BB48BF95B8AF66CE7FFF45C36163@NYMBX02.bcna.corp> References: <60CDCA83B420BB48BF95B8AF66CE7FFF45C36163@NYMBX02.bcna.corp> Message-ID: There is also chocolatey .NET package for pythonnet not maintained since 2014. The author is not responding. On Fri, Jun 26, 2015 at 9:50 AM, Adam Klein wrote: > Congrats and thank you! > > > > *From:* PythonDotNet [mailto:pythondotnet-bounces+aklein= > bmcm.com at python.org] *On Behalf Of *Tony Roberts > *Sent:* Friday, June 26, 2015 5:43 AM > *To:* pythondotnet at python.org > *Subject:* [Python.NET] pythonnet 2.0.0 released > > > > Hi, > > > > I've finally gotten round to finishing off the last couple of things that > were blocking an 'official' 2.0.0 release (to do with packaging as > wheels/source dist). > > > > There is now a 2.0.0 release available on PyPI ( > https://pypi.python.org/pypi/pythonnet), with binary wheels for Windows > (32 and 64 bit) and a source distribution for Linux and Mac. > > > > The next task will be to integrate the changes from the > renshawbay/pythonnet fork to add Python 3 support. > > > > cheers, > > Tony > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet > -------------- next part -------------- An HTML attachment was scrubbed... URL: From denis.akhiyarov at gmail.com Fri Jan 29 01:59:49 2016 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Fri, 29 Jan 2016 00:59:49 -0600 Subject: [Python.NET] Memory leak problem in function "AsManagedObject" In-Reply-To: References: Message-ID: I created a pull to fix this. Such calls should be inside using blocks, like it was for other methods in PyObject. This particular one was missed. It would be nice if any static analyzers revealed this. I tried PVS-Studio and it did not reveal any problems on pythonnet, except handling of Double.MaxValue & Double.MinValue. On Wed, Jan 20, 2016 at 2:53 AM, Tony Roberts wrote: > Hi Eliana, > > great, glad you were able to find the problem. I'll make that change in > github. > > thanks, > Tony > > On Tue, Jan 19, 2016 at 8:46 PM Eliana Mendes > wrote: > >> Thank you all for the answers! >> >> >> I got the source code from the githup and built it myself, as you >> suggested. Unfortunately the memory leak problem remains even with this >> latest branch. But this time I was able to figure out where the problem is! >> >> >> >> The problem is not inside the ?AsMangedObject?? as I thought before, but >> instead it is inside the ?GetItem(int index)? method which is inside the " >> *pyobject*" class. This method creates a new instance of *PyInt *and a >> new instance of *PyObject*. Those are exactly the objects that my memory >> profiler was showing. In order to fix my problem I had to first edit >> this method to be like this: >> >> >> public virtual PyObject GetItem(int index) { >> >> PyInt key = new PyInt(index); >> >> PyObject item = GetItem((PyObject)key); >> >> key.Dispose(); >> >> return item; >> >> } >> >> >> >> After doing that, in my code, I had to add a dispose for myTuple[i]. So I >> changed my code to look something similar to this: >> >> >> >> PyObject tupleResult = myTuple[0]; >> >> results[0] = >> (double)tupleResult.AsManagedObject(typeof(double)); >> >> tupleResult.Dispose(); >> >> >> >> By doing those changes the problem was entirely fixed! >> >> >> >> I?m not sure who to contact exactly about changing the source code, but I >> would highly recommend in making those changes in the ?GetItem? method in >> order to avoid someone else having the same memory problem. >> >> >> >> Thanks a lot for all your help! >> >> >> Best regards, >> >> >> Eliana >> >> 2016-01-18 16:54 GMT-06:00 Denis Akhiyarov : >> >>> Your binaries are rather outdated.. >>> >>> Here is the latest branch: >>> >>> https://github.com/pythonnet/pythonnet/tree/develop >>> >>> And binaries here: >>> >>> https://pypi.python.org/pypi/pythonnet/2.1.0.dev1 >>> >>> http://www.lfd.uci.edu/~gohlke/pythonlibs/#pythonnet >>> >>> On Mon, Jan 18, 2016, 4:47 PM Eliana Mendes >>> wrote: >>> >>>> Hello Tony, >>>> >>>> >>>> >>>> Thanks a lot for your answer! I actually just got directly the >>>> ?Python.Runtime.dll? from the download link in sourceforge: >>>> http://sourceforge.net/projects/pythonnet/files/. But from the >>>> description I see that the last update of that one was done in 2013. Would >>>> there be a newer version somewhere else that I could get? Perhaps this >>>> version I?m using is out of date and you have a newer one. Let me know if >>>> that?s the case. >>>> >>>> >>>> >>>> I tried your suggestion of putting the ?using? statement for the tuple >>>> objects, and also for ?myTuple?, and the memory is still increasing a lot. >>>> I?ve made a memory profile to see which objects are being retained and >>>> after I ran that statement 5 thousand times I got this: >>>> >>>> >>>> [image: Imagem inline 1] >>>> >>>> >>>> As you can see more that 12 thousand instances of ?PyInt? and more than >>>> 6 thousand of ?PyObject? are created . Apparently it is creating these >>>> ?PyInt? and ?PyObjects? somewhere inside the ?AsManagedObject?, because I >>>> don?t have PyInt objects anywhere in my code and this just happens when I >>>> call ?AsManagedObject?. >>>> >>>> >>>> >>>> Let me know if there is a newer version that could probably have that >>>> problem fixed which I am not aware of. >>>> >>>> >>>> I appreciate a lot your help! >>>> >>>> >>>> >>>> Best regards, >>>> >>>> Eliana >>>> >>>> 2016-01-17 6:05 GMT-06:00 Tony Roberts : >>>> >>>>> Hi Eliana, >>>>> >>>>> 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? >>>>> >>>>> 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). >>>>> >>>>> PyTuple myTuple = PyTuple.AsTuple(result); >>>>> >>>>> double result0; >>>>> using (var item0 = myTuple[0]) >>>>> result0 = (double)item0.AsManagedObject(typeof(double)); >>>>> >>>>> double result1; >>>>> using (var item1 = myTuple[1]) >>>>> result1 = (double)item1.AsManagedObject(typeof(double)); >>>>> >>>>> myTuple.Dispose(); >>>>> >>>>> 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. >>>>> >>>>> Regards, >>>>> Tony >>>>> >>>>> >>>>> On Fri, Jan 15, 2016 at 8:06 PM Eliana Mendes < >>>>> eliana.mendesp at gmail.com> wrote: >>>>> >>>>>> Hello experts, >>>>>> >>>>>> >>>>>> >>>>>> I'm having a memory leak problem when using the >>>>>> function AsManagedObject(typeof(double)). Basically I have something like >>>>>> this: >>>>>> >>>>>> >>>>>> >>>>>> PyTuple myTuple = PyTuple.AsTuple(result); >>>>>> >>>>>> double result0 = (double)myTuple[0].AsManagedObject(typeof(double)); >>>>>> >>>>>> double result1 = (double)myTuple[1].AsManagedObject(typeof(double)); >>>>>> >>>>>> myTuple.Dispose(); >>>>>> >>>>>> >>>>>> >>>>>> 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 >>>>>> >>>>>> _________________________________________________ >>>>>> Python.NET mailing list - PythonDotNet at python.org >>>>>> https://mail.python.org/mailman/listinfo/pythondotnet >>>>> >>>>> >>>>> _________________________________________________ >>>>> Python.NET mailing list - PythonDotNet at python.org >>>>> https://mail.python.org/mailman/listinfo/pythondotnet >>>>> >>>> >>>> _________________________________________________ >>>> Python.NET mailing list - PythonDotNet at python.org >>>> https://mail.python.org/mailman/listinfo/pythondotnet >>> >>> >>> _________________________________________________ >>> Python.NET mailing list - PythonDotNet at python.org >>> https://mail.python.org/mailman/listinfo/pythondotnet >>> >> >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> https://mail.python.org/mailman/listinfo/pythondotnet > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image.png Type: image/png Size: 70883 bytes Desc: not available URL: From denis.akhiyarov at gmail.com Sun Jan 31 01:32:21 2016 From: denis.akhiyarov at gmail.com (Denis Akhiyarov) Date: Sun, 31 Jan 2016 00:32:21 -0600 Subject: [Python.NET] Debugging CPYTHON embedded in .NET In-Reply-To: References: Message-ID: Tony, thank you for suggesting PyCharm. Although I found code refactoring much nicer in PyCharm than PTVS, the debugger has yet to match PTVS :) I have multiple open issues for PyCharm/PTVS debuggers: https://youtrack.jetbrains.com/issue/PY-16844 https://github.com/Microsoft/PTVS/issues/552 Any solution or alternative remote debuggers would be appreciated. Thanks, Denis On Fri, Jul 10, 2015 at 3:23 AM, Tony Roberts wrote: > Hi Denis, > > you can use the remote debugger in PyCharm to attach to your .NET process. > It requires a small bit of python code in your application to make it > connect to the PyCharm debug server, but it works very well. > > See the instructions here: > http://blog.jetbrains.com/pycharm/2010/12/python-remote-debug-with-pycharm/ > > I've got an open request to enhance the new 'attach to process' feature > that appeared in 4.0 so that it could attach to processes embedding python > and not just python.exe (https://youtrack.jetbrains.com/issue/PY-14181), > but for now using the debug server is your best option. > > Best regards, > Tony > > > On Thu, Jul 9, 2015 at 4:51 PM Denis Akhiyarov > wrote: > >> Dear users and developers of PythonNET: >> >> How do you debug CPython embedded in . NET? >> >> Did you find any reliable way to do this with IDE such as PTVS or Pycharm? >> >> PTVS offers mixed-mode and remote debugging, none of which seem to be >> usable with PythonNET. >> >> Thanks, >> Denis >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> https://mail.python.org/mailman/listinfo/pythondotnet > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > https://mail.python.org/mailman/listinfo/pythondotnet > -------------- next part -------------- An HTML attachment was scrubbed... URL: