<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.E-MailFormatvorlage17
        {mso-style-type:personal-reply;
        font-family:"Arial","sans-serif";
        color:windowtext;
        font-weight:normal;
        font-style:normal;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="DE" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif"">Hi,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif"">IronPython runs on .NET which has a very different garbage collector than the one used in cPython.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif"">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
<a href="https://docs.python.org/2/library/gc.html">https://docs.python.org/2/library/gc.html</a>).<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif"">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif"">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.)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif"">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif"">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).<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif""><o:p> </o:p></span></p>
<div>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black">Best regards<br>
<br>
Markus Schaber</span><span lang="EN-US"><br>
<br>
</span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#636363">CODESYS<sup>®</sup></span></b><span lang="EN-US">
</span><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial","sans-serif";color:#B1B2B3">a trademark of 3S-Smart Software Solutions GmbH</span><span lang="EN-US">
<br>
</span><b><span lang="EN-US" style="font-size:2.0pt;font-family:"Arial","sans-serif";color:#636363"><br>
</span></b><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#636363">Inspiring Automation Solutions
</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#636363"><o:p></o:p></span></p>
<div class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#636363">
<hr size="1" width="643" style="width:482.25pt" noshade="" style="color:#636363" align="left">
</span></div>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#636363">3S-Smart Software Solutions GmbH
<br>
Dipl.-Inf. Markus Schaber | Product Development Core Technology <br>
Memminger Str. 151 | 87439 Kempten | Germany <br>
Tel. +49-831-54031-979 | Fax +49-831-54031-50 <br>
<br>
E-Mail: </span><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#636363"><a href="mailto:m.schaber@codesys.com"><span lang="EN-US" style="color:#E3000F;text-decoration:none">m.schaber@codesys.com</span></a></span><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#636363">
 | Web: </span><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#636363"><a href="http://www.codesys.com"><span lang="EN-US" style="color:#E3000F;text-decoration:none">codesys.com</span></a></span><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#636363">
 | CODESYS store: </span><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#636363"><a href="http://store.codesys.com"><span lang="EN-US" style="color:#E3000F;text-decoration:none">store.codesys.com</span></a></span><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#636363">
<br>
CODESYS forum: </span><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#636363"><a href="http://forum.codesys.com"><span lang="EN-US" style="color:#E3000F;text-decoration:none">forum.codesys.com</span></a></span><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#636363">
<br>
<br>
</span><i><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial","sans-serif";color:#636363">Managing Directors: Dipl.Inf. Dieter Hess, Dipl.Inf. Manfred Werner</span></i><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial","sans-serif";color:#636363">
 | <i>Trade register: Kempten HRB 6186</i> | <i>Tax ID No.: DE 167014915</i></span><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#636363">
<o:p></o:p></span></b></p>
<div class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#636363">
<hr size="1" width="643" style="width:482.25pt" noshade="" style="color:#636363" align="left">
</span></b></div>
</div>
<p class="MsoNormal"><i><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial","sans-serif";color:#636363">This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received
<br>
this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure
<br>
or distribution of the material in this e-mail is strictly forbidden.</span></i><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#636363">
</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Arial","sans-serif""><o:p></o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Ironpython-users [mailto:ironpython-users-bounces+m.schaber=codesys.com@python.org]
<b>On Behalf Of </b>Djordje Spasic via Ironpython-users<br>
<b>Sent:</b> Monday, December 21, 2015 5:19 PM<br>
<b>To:</b> ironpython-users@python.org<br>
<b>Subject:</b> [Ironpython-users] Delete a large object in ironpython, and releasing the memory?<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div id="yui_3_16_0_1_1450604454550_18806">
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:"Verdana","sans-serif";color:black">I am a creating a huge mesh object (some 900 megabytes in size) in Rhino3d application by using its ironpython 2.7 interpreter.<o:p></o:p></span></p>
</div>
<div id="yui_3_16_0_1_1450604454550_19038">
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:"Verdana","sans-serif";color:black">Once I am done with analysing this mesh, I would like to somehow delete it from the memory.<br id="yui_3_16_0_1_1450604454550_18985">
<br id="yui_3_16_0_1_1450604454550_18987">
I did a bit of search on stackoverflow.com, and I found out that "<i id="yui_3_16_0_1_1450604454550_19087">del</i>" statement will only delete the reference to mentioned mesh. Not the mesh object itself.<br id="yui_3_16_0_1_1450604454550_18989">
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.<br id="yui_3_16_0_1_1450604454550_18991">
<br id="yui_3_16_0_1_1450604454550_18993">
Is "<i id="yui_3_16_0_1_1450604454550_19253">gc.collect()</i>" the only way by which I could instantly release the memory, and there for somehow remove the mentioned large mesh from the memory?<br id="yui_3_16_0_1_1450604454550_18995">
I've also found replies on stackoverflow.com which state that "<i id="yui_3_16_0_1_1450604454550_19129">gc.collect()</i>" should be avoided (at least when it comes to regular python, not specifically ironpython).<br id="yui_3_16_0_1_1450604454550_18997">
I've also find <a href="http://stackoverflow.com/questions/1316767/how-can-i-explicitly-free-memory-in-python" id="yui_3_16_0_1_1450604454550_19247">comments on stackoverflow which claim that in IronPython it is not even guaranteed the memory will be released</a>
 if nothing else is holding a reference.<br id="yui_3_16_0_1_1450604454550_18999">
<br id="yui_3_16_0_1_1450604454550_19001">
Any comments on all these issues?<br id="yui_3_16_0_1_1450604454550_19003">
<br id="yui_3_16_0_1_1450604454550_19005">
Is it even possible to instantly free the memory from the deleted large object in ironpython (2.7)?<br id="yui_3_16_0_1_1450604454550_19007">
<br id="yui_3_16_0_1_1450604454550_19009">
Thank you for the reply.<br>
<br>
Kind regards,<br>
Djordje Spasic<o:p></o:p></span></p>
</div>
<div id="yui_3_16_0_1_1450604454550_19038">
<p class="MsoNormal" style="background:white"><span style="font-size:10.0pt;font-family:"Verdana","sans-serif";color:black"><o:p> </o:p></span></p>
</div>
</div>
</div>
</div>
</body>
</html>