<div dir="ltr">OK, this is definitely surprising. &nbsp;<div><br></div><div>Is it correct to &nbsp;assume that by setting the compilation to non-optimized mode, the compilation result will behave like a normal .Net object in being subjected to normal GC collection when it&#39;s out of scope? Or do I have to explicitly set GC collection after usage?</div>
<div><br></div><div>Dody G.<br><div><br><div class="gmail_quote">On Fri, Jan 2, 2009 at 7:59 PM, Dino Viehland <span dir="ltr">&lt;<a href="mailto:dinov@microsoft.com">dinov@microsoft.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">









<div lang="EN-US" link="blue" vlink="purple">

<div>

<p><span style="font-size:11.0pt;color:#1F497D">This would appear to be a bad default value for compiling.&nbsp; You
can explicitly disable compiling the code as optimized and it will be fully
collectible:</span></p>

<p><span style="font-size:11.0pt;color:#1F497D">&nbsp;</span></p>

<p style="margin-left:.5in"><span style="font-size:11.0pt;color:#1F497D">var runtime =
Python.CreateRuntime();</span></p>

<p style="margin-left:.5in"><span style="font-size:11.0pt;color:#1F497D">var engine =
runtime.GetEngine(&quot;py&quot;);</span></p>

<p style="margin-left:.5in"><span style="font-size:11.0pt;color:#1F497D">var sum = 0.0;</span></p>

<p style="margin-left:.5in"><b><span style="font-size:11.0pt;color:#1F497D">PythonCompilerOptions pco =
(PythonCompilerOptions)engine.GetCompilerOptions();</span></b></p>

<p style="margin-left:.5in"><b><span style="font-size:11.0pt;color:#1F497D">pco.Module &amp;=
~ModuleOptions.Optimized;</span></b></p>

<p><b><span style="font-size:11.0pt;color:#1F497D">&nbsp;</span></b></p>

<p style="margin-left:.5in"><span style="font-size:11.0pt;color:#1F497D">while (true)</span></p>

<p style="margin-left:.5in"><span style="font-size:11.0pt;color:#1F497D">{</span></p>

<p style="margin-left:1.0in"><span style="font-size:11.0pt;color:#1F497D">var code =
engine.CreateScriptSourceFromString(&quot;1.0+2.0&quot;).Compile(<b>pco</b>);</span></p>

<p style="margin-left:1.0in"><span style="font-size:11.0pt;color:#1F497D">sum +=
code.Execute&lt;double&gt;();</span></p>

<p style="margin-left:1.0in"><span style="font-size:11.0pt;color:#1F497D">GC.Collect();</span></p>

<p style="margin-left:1.0in"><span style="font-size:11.0pt;color:#1F497D">GC.WaitForPendingFinalizers();</span></p>

<p style="margin-left:1.0in"><span style="font-size:11.0pt;color:#1F497D">GC.Collect();</span></p>

<p style="margin-left:1.0in"><span style="font-size:11.0pt;color:#1F497D">Console.WriteLine(sum);</span></p>

<p style="margin-left:.5in"><span style="font-size:11.0pt;color:#1F497D">}</span></p>

<p><span style="font-size:11.0pt;color:#1F497D">&nbsp;</span></p>

<p><span style="font-size:11.0pt;color:#1F497D">I am inclined to change this, or at least add some other way
that makes this more discoverable (e.g. via the Python class).&nbsp; But I think
changing the default should probably wait until 2.1 as it could have some small
perf surprises for people who are expecting it to be in the more optimal form
(globals will be ~10% slower).&nbsp; Longer term we're working w/ the CLR team to
get the best of both worlds.</span></p>

<p><span style="font-size:11.0pt;color:#1F497D">&nbsp;</span></p>

<p><span style="font-size:11.0pt;color:#1F497D">&nbsp;</span></p>

<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">

<p><b><span style="font-size:10.0pt">From:</span></b><span style="font-size:10.0pt">
<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>] <b>On
Behalf Of </b>Dody Gunawinata<br>
<b>Sent:</b> Wednesday, December 31, 2008 4:35 AM<br>
<b>To:</b> Discussion of IronPython<br>
<b>Subject:</b> Re: [IronPython] Embedding IronPython</span></p>

</div><div><div></div><div class="Wj3C7c">

<p>&nbsp;</p>

<p style="margin-bottom:12.0pt">Please we need more vote on the
memory leak issue because it has huge impact on the usage of Iron Python for
the web environment as well.</p>

<div>

<p>On Wed, Dec 31, 2008 at 11:50 AM, Christian Schmidt &lt;<a href="mailto:christian2.schmidt@gmx.de" target="_blank">christian2.schmidt@gmx.de</a>&gt;
wrote:</p>

<p style="margin-bottom:12.0pt">Hi Josh,</p>

<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">

<p>CompiledCode cc = src.Compile();</p>

</blockquote>

<p><br>
This will leak memory. So you will run out of memory after a while (in our case
after 100&#39;000 compiles on x86).<br>
[<a href="http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=20399" target="_blank">http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=20399</a>]</p>

<div>

<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">

<p style="margin-bottom:12.0pt">&nbsp;</p>

<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">

<p>Is this going to work or will I run into threading problems?
&nbsp;In other words, is the ScriptEngine thread-safe? &nbsp;Will it serialize
all of my cc.Execute() calls? &nbsp;Any other insight into its behavior in this
regard would be appreciated.</p>

</blockquote>

</blockquote>

<p>&nbsp;</p>

</div>

<p>I think globals and imports will be shared. So modifying
them might give unexpected results.<br>
<br>
Cheers,<br>
<span style="color:#888888">Christian</span></p>

<div>

<div>

<p><br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a></p>

</div>

</div>

</div>

<p style="margin-bottom:12.0pt"><br>
<br clear="all">
<br>
-- <br>
<a href="http://nomadlife.org" target="_blank">nomadlife.org</a></p>

</div></div></div>

</div>


</blockquote></div><br><br clear="all"><br>-- <br><a href="http://nomadlife.org">nomadlife.org</a><br><br>
</div></div></div>