Friday, May 18, 2007

Memory Debugging in .NET applications

Long time ago I found a post regarding memory debugging in .NET applications:
Analyzing Common CLR Performance Problems

That post address lots of memory leak types, while usually I encouter memory leaks from the heap. Here's the summary how to find heap memory leaks:

1. Start the windows debugger: WinDbg (can be downloaded from here).

2. Attach to the target .NET process

3. Load the SOS module, in the WinDbg console write:
.loadby sos mscorwks

4. List all the allocated objects:
!dumpheap -stat

At this point you can break & resume the program as you wish.
Other Useful commands:
!finalizequeue - show the list of objects waiting for finalize thread
!threads - running threads
!eeheap -gc - show the object generations in the GC

Full (?) list of commands can be found here

No comments: