Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The best explanation I've seen is in Chapter 7 of the free <a href="http://codebetter.com/karlseguin/2008/06/25/foundations-of-programming-ebook/" rel="nofollow noreferrer">Foundations of Programming e-book</a>.</p> <p>Basically, in <strong>.NET</strong> a memory leak occurs when referenced objects are rooted and thus cannot be garbage collected. This occurs accidentally when you hold on to references beyond the intended scope.</p> <p>You'll know that you have leaks when you start getting OutOfMemoryExceptions or your memory usage goes up beyond what you'd expect (<strong>PerfMon</strong> has nice memory counters). </p> <p>Understanding <strong>.NET</strong>'s memory model is your best way of avoiding it. Specifically, understanding how the garbage collector works and how references work — again, I refer you to chapter 7 of the e-book. Also, be mindful of common pitfalls, probably the most common being events. If object <strong>A</strong> is registered to an event on object <strong>B</strong>, then object <strong>A</strong> will stick around until object <strong>B</strong> disappears because <strong>B</strong> holds a reference to <strong>A</strong>. The solution is to unregister your events when you're done. </p> <p>Of course, a good memory profile will let you see your object graphs and explore the nesting/referencing of your objects to see where references are coming from and what root object is responsible (<a href="http://www.red-gate.com/products/ants_memory_profiler/index.htm" rel="nofollow noreferrer">red-gate ants profile</a>, JetBrains dotMemory, <a href="http://memprofiler.com/" rel="nofollow noreferrer">memprofiler</a> are really good choices, or you can use the text-only <strong>WinDbg</strong> and <strong>SOS</strong>, but I'd strongly recommend a commercial/visual product unless you're a real guru).</p> <p>I believe unmanaged code is subject to its typical memory leaks, except that shared references are managed by the garbage collector. I could be wrong about this last point.</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. 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.
 

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