Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The best explanation of how the garbage collector works is in Jeff Richters <a href="https://www.microsoftpressstore.com/store/clr-via-c-sharp-9780735667457" rel="noreferrer">CLR via C#</a> book, (Ch. 20). Reading this gives a great grounding for understanding how objects persist.</p> <p>One of the most common causes of rooting objects accidentally is by hooking up events outisde a class. If you hook up an external event </p> <p>e.g.</p> <pre><code>SomeExternalClass.Changed += new EventHandler(HandleIt); </code></pre> <p>and forget to unhook to it when you dispose, then SomeExternalClass has a ref to your class.</p> <p>As mentioned above, the <a href="http://memprofiler.com" rel="noreferrer">SciTech memory profiler</a> is excellent at showing you roots of objects you suspect are leaking. </p> <p>But there is also a very quick way to check a particular type is just use WnDBG (you can even use this in the VS.NET immediate window while attached):</p> <pre><code>.loadby sos mscorwks !dumpheap -stat -type &lt;TypeName&gt; </code></pre> <p>Now do something that you think will dispose the objects of that type (e.g. close a window). It's handy here to have a debug button somewhere that will run <code>System.GC.Collect()</code> a couple of times.</p> <p>Then run <code>!dumpheap -stat -type &lt;TypeName&gt;</code> again. If the number didn't go down, or didn't go down as much as you expect, then you have a basis for further investigation. (I got this tip from a seminar given by <a href="http://www.thinktecture.com/staff/ingo" rel="noreferrer">Ingo Rammer</a>).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload