[Ironpython-users] Delete a large object in ironpython, and releasing the memory?
Markus Schaber
m.schaber at codesys.com
Tue Dec 22 05:04:45 EST 2015
Hi,
IronPython runs on .NET which has a very different garbage collector than the one used in cPython.
cPython uses reference counting, and a synchronous collector which collects cyclic garbage. Thus, objects which are not parts of cycles are guaranteed to be collected in the very moment when the last reference to them is removed, and the “del” statement is one way this could happen. (Just setting the variable reference None or some other object, or the variable dropping out of scope are some other possibilities.) However, collection of cyclic garbage happens somewhere later, depending on the thresholds of newly allocated objects. (See https://docs.python.org/2/library/gc.html).
IronPython uses the .NET garbage collector which does not employ reference counting (at least not in Microsoft .NET, Mono and Rotor). Garbage collection always happens at a non-deterministic time – usually triggered by the “memory pressure” of the current process, which is mostly related to the amount of allocated memory over time.
In both cases, gc.collect() forces a complete garbage collection to occur now. (Actually, gc.collect() on IronPython mainly calls to System.GC.Collect() for this purpose, apart from performing some IronPython specific cleanups.)
Usually, there is no need to actively call the garbage collector – however, if you really have several hundred MBs of Memory which you want to release back to the OS immediately, I think it is justified to call the garbage collector. Especially if your process will not allocate any memory soon, the GC might not kick in for a long time if you don’t call it explicitly.
However, I want to emphasize that this is a special case, and generally, “normal” applications do not need to call the garbage collector explicitly, and should not (as frequent calls to the GC will impact performance negatively).
Best regards
Markus Schaber
CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions
________________________________
3S-Smart Software Solutions GmbH
Dipl.-Inf. Markus Schaber | Product Development Core Technology
Memminger Str. 151 | 87439 Kempten | Germany
Tel. +49-831-54031-979 | Fax +49-831-54031-50
E-Mail: m.schaber at codesys.com<mailto:m.schaber at codesys.com> | Web: codesys.com<http://www.codesys.com> | CODESYS store: store.codesys.com<http://store.codesys.com>
CODESYS forum: forum.codesys.com<http://forum.codesys.com>
Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner | Trade register: Kempten HRB 6186 | Tax ID No.: DE 167014915
________________________________
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received
this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure
or distribution of the material in this e-mail is strictly forbidden.
From: Ironpython-users [mailto:ironpython-users-bounces+m.schaber=codesys.com at python.org] On Behalf Of Djordje Spasic via Ironpython-users
Sent: Monday, December 21, 2015 5:19 PM
To: ironpython-users at python.org
Subject: [Ironpython-users] Delete a large object in ironpython, and releasing the memory?
I am a creating a huge mesh object (some 900 megabytes in size) in Rhino3d application by using its ironpython 2.7 interpreter.
Once I am done with analysing this mesh, I would like to somehow delete it from the memory.
I did a bit of search on stackoverflow.com, and I found out that "del" statement will only delete the reference to mentioned mesh. Not the mesh object itself.
And that after some time, the mesh object will eventually get garbage collected. At least this is what some users on stackoverflow say about the regular cpython.
Is "gc.collect()" the only way by which I could instantly release the memory, and there for somehow remove the mentioned large mesh from the memory?
I've also found replies on stackoverflow.com which state that "gc.collect()" should be avoided (at least when it comes to regular python, not specifically ironpython).
I've also find comments on stackoverflow which claim that in IronPython it is not even guaranteed the memory will be released<http://stackoverflow.com/questions/1316767/how-can-i-explicitly-free-memory-in-python> if nothing else is holding a reference.
Any comments on all these issues?
Is it even possible to instantly free the memory from the deleted large object in ironpython (2.7)?
Thank you for the reply.
Kind regards,
Djordje Spasic
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20151222/8d05c1ba/attachment.html>
More information about the Ironpython-users
mailing list