<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"><meta name="Generator" content="Microsoft Word 14 (filtered medium)"><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:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        text-align:right;
        direction:rtl;
        unicode-bidi:embed;
        font-size:11.0pt;
        font-family:"Calibri","sans-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;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        text-align:right;
        direction:rtl;
        unicode-bidi:embed;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
span.EmailStyle22
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle23
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle24
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle25
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle26
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle27
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle28
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.WordSection1
        {page:WordSection1;}
--></style></head><body lang="EN-US" link="blue" vlink="purple"><div class="WordSection1"><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">I should have mentioned that I can&#39;t run in debug mode. On the other hand I do have a windbg sessions on my application (one session when the heap is small and one when it is big).</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">Can you tell me the object types that I should like for in the managed code, such that if their number is increasing then I can tell they are responsible for the leaks?</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D"> </span></p><div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
<b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Dino Viehland<br>
<b>Sent:</b> Wednesday, October 13, 2010 10:01 PM<br><b>To:</b> Discussion of IronPython<br><b>Subject:</b> Re: [IronPython] HostCodeHeap leakage?</span></p></div></div><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
 </p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">If you build from source you could set some breakpoints in AssemblyGen.cs in the DefineType method.  You can also set one in DelegateUtils.cs <b>and</b> DelegateHelpers.cs in DefineDelegateType.  I think those are all the places where we are creating uncollectible types.  If we’re continuously hitting those breakpoints after you believe your app has reached steady state then something is going wrong.</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D"> </span></p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">This code <a href="http://www.koders.com/cpp/fid5CC8EACFCC85496B49B8CF83BD05AB36DE691E90.aspx">http://www.koders.com/cpp/fid5CC8EACFCC85496B49B8CF83BD05AB36DE691E90.aspx</a> leads me to believe the HostCodeHeap might also be used for DynamicMethods.  If that is the case then the other place to look would be if FunctionCode objects are being re-created repeatedly.  That will happen if there’s exec/eval/compile calls which are happening and if those objects are being kept alive then we could be growing the heap over time.  </span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D"> </span></p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">There’s also some complicated code which deals with keeping a list of all code that is alive.  We do cleanup this list, and the list is a list of weak references so it shouldn’t actually keep the code alive, but you could put some breakpoints at FunctionCode.RegisterFunctionCode and FunctionCode.CodeCleanup to see if that list is growing boundlessly (which it would be if something was keeping code objects alive after an exec/eval/compile).  </span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D"> </span></p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">Another place where code generation could be occurring would be w/ regexes.  If you are dynamically generating reg-exes, or executing a huge different variety of them over time, and they’re compiled, then the compiled regexes could be staying in memory.  There is a regex cache and you can clear it by calling re.purge().  But it should only cache up to 100 regexes.</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D"> </span></p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">A final possible thing to investigate might be what happens if you throw away the entire ScriptEngine instance.  Here you could try re-cycling the ScriptEngine say every 6 hours and see if the problem goes away.  If that fixes the problem then it’s likely that it is one of the things I mentioned (or some other cache that’s per-runtime).  At least that would start to narrow it down vs. some potentially global state (like the subtype list which is shared across ScriptEngines).</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D"> </span></p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">That’s a bunch of different things to look at – hopefully it’ll give some insight into what’s going on and help track down the issue.</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D"> </span></p><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt"><div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Idan Zaltzberg<br>
<b>Sent:</b> Wednesday, October 13, 2010 12:12 AM<br><b>To:</b> Discussion of IronPython<br><b>Subject:</b> Re: [IronPython] HostCodeHeap leakage?</span></p></div></div><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
 </p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">I tried what you suggested (changed </span><span style="font-size:10.0pt;font-family:Consolas">setup.DebugMode = <span style="color:blue">false</span>;</span>)</p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">But still I get the same behavior:</span></p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
<span style="color:#1F497D">The &quot;Jit Code Heap&quot; increases from about 17MB to 230MB in 2 days.</span></p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">Is there a way to verify from the IronPython code that DebugMode is off?</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">Is there anything else I can do (other startup settings?) to decrease/understand the increase in HostCodeHeap objects?</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">Thanks.</span></p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D"> </span></p>
<div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Dino Viehland<br>
<b>Sent:</b> Tuesday, October 05, 2010 6:59 PM<br><b>To:</b> Discussion of IronPython<br><b>Subject:</b> Re: [IronPython] HostCodeHeap leakage?</span></p></div></div><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
 </p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">Yep, DebugMode is the same as –X:Debug.  In general I’d suggest making this configurable somehow and only turn it on if you’re actually debugging.  It’s unfortunate that we can’t offer both debugging &amp; collectability but right now that’s simply a limitation of the CLR and/or our lack of a separate VS debug engine which can debug Python code.</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D"> </span></p><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt"><div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Idan Zaltzberg<br>
<b>Sent:</b> Tuesday, October 05, 2010 9:09 AM<br><b>To:</b> Discussion of IronPython<br><b>Subject:</b> Re: [IronPython] HostCodeHeap leakage?</span></p></div></div><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
 </p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">Im running using the engine from a hosting app.</span></p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
<span style="color:#1F497D">We have these lines in the startup:</span></p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="font-size:10.0pt;font-family:Consolas;color:#2B91AF">ScriptRuntimeSetup</span><span style="font-size:10.0pt;font-family:Consolas"> setup = <span style="color:blue">new</span> <span style="color:#2B91AF">ScriptRuntimeSetup</span>();<br>
setup.DebugMode = <span style="color:blue">true</span>;</span></p><pre style="margin-bottom:12.0pt"><span style="font-family:Consolas;color:#2B91AF">ScriptRuntime</span><span style="font-family:Consolas"> runtime = <span style="color:#2B91AF">Python</span>.CreateRuntime(setup.Options);</span></pre>
<pre><span style="font-family:Consolas">engine = runtime.GetEngine(<span style="color:#A31515">&quot;py&quot;</span>);</span></pre><pre><span style="font-family:Consolas"> </span></pre><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
<span style="color:#1F497D">Is this is the same like –X:Debug?</span></p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">You reckon this could be the cause?</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D"> </span></p><div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
<b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Dino Viehland<br>
<b>Sent:</b> Tuesday, October 05, 2010 5:53 PM<br><b>To:</b> Discussion of IronPython<br><b>Subject:</b> Re: [IronPython] HostCodeHeap leakage?</span></p></div></div><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
 </p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">My guess is that’s code in the JIT heap that’s building up but I’m not 100% certain.  How is your code being executed?  Do you have the debug option (-D or –X:Debug) enabled?  To support debug mode we need to produce uncollectible code which could be building up.</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D"> </span></p><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt"><div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Idan Zaltzberg<br>
<b>Sent:</b> Tuesday, October 05, 2010 2:26 AM<br><b>To:</b> Discussion of IronPython<br><b>Subject:</b> [IronPython] HostCodeHeap leakage?</span></p></div></div><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
 </p><p>I am trying to find a memory/&quot;performance&quot; leak in an Ipy application.</p><p>Using WINDBG (!eeheap -loader), we noticed the that the LoaderHeap is getting bigger (150MB increase per day). From the !eeheap output it seems that the increase is due to HostCodeHeap (objects?).</p>
<p>As I understand these objects might be created by Ipy infra, is that right?</p><p>Is there anyway I can get more info on their content, or prevent them from growing?</p><p>Thanks</p><p class="MsoNormal" dir="RTL"><span dir="LTR"> </span></p>
</div></div></div></div></body></html>