Managed Memory Analysis

There are many different approaches to analyzing .NET managed memory. From the simplest, watching
memory grow via Task Manager, to using Performance Profiler, to employing a debugging tool. Unless
the leak is obvious, the only way to truly efficiently reveal the nature of a leak is to use a tool.
Otherwise, you’ll be poking in the dark indefinitely.

Remember that a part that seems to be leaking will often not be the source of the leak, just an innocent
side-effect. In .NET, an object is left in memory because another object is holding a reference to it. Only
through the use of a tool can the identity of the offending object be efficiently revealed and corrective
action taken.

(The only other option is costly manual, code analysis, which is often more costly than it was to
originally write the offending code in the first place.)


When it comes to memory analysis techniques, the net is full of great commentary and anecdote about
different approaches. You will need to study these to understand what to look for. In the end I’m sure
you’ll find yourself primarily evaluating objects that are revealed to be GC roots.


Microsoft provides a free tool, WinDbg, for debugging failure cases and running processes. A .NET add-
on called SOS allows managed application analysis within the context of this tool. This tool is powerful,
but crude. While it does have a GUI, its usage is still command line based.

MS Debug Tools Home Page:

Other Vendors

There are many vendors on the market selling memory profiling tools. The latest versions of a few are
powerful and easy to use, though they can be somewhat expensive. My favorite is version 5.1 of the
ANTS Memory Profiler from Red Gate Software. With this version, they have revolutionized the display
of .NET object relations making it very efficient to identify leaks.

Red Gate ANTS Memory Profiler:

Last edited Oct 2, 2009 at 2:37 AM by theMont, version 1


No comments yet.