.NET Leak Hunting with SOS

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

In last at least 10 years I figured out that a day of .NET managed developer is more easier than a day o C++ dev. In the decade before .NET I was spending a majority of a time by looking foe memory overruns and memory leaks. If you ever did such job for a longer time you will agree that not an amazing task. Unfortunately there are also situation when .NET  application can leak too. Thinking positive I always say “Be happy that memory overruns are gone at least”.
My intension with this post is simply to paste few words which helps (me or you) tomorrow to remember what is my favor way to fix such issues. I really like very much Visual Studio and all those tools around it. But in very hard cases, which are according to murphy's low common cases all these tolls do not help much instead of one; the hardest one. Son of Strike.

It is installed in folder: %windir%\Microsoft.NET\Framework\<version>\sos.dll

To load it in VS, type following command line in Immediate Window:

.load sos

When looking for leaks type !dumpheap -type MyNamespace.MyType

This command dumps the portion of heap space occupied by instances of type MyNamespace.MyType. You can also type MyNamespace only and SOS will show the heap occupied by instances of all types of that namespace. I usually implement an endless loop in some part of program which probably leaks and stop after few steps in the loop to take a look on instance counter. In the case below this is 8.

!dumpheap -type MyNamespace.MyType
Address       MT     Size
026fe21c 04999024      272    
026ff2f4 04999024      272    
0278610c 04999024      272    
0278be1c 04999024      272    
027fcc00 04999024      272    
0281d258 04999024      272    
0288cde4 04999024      272    
028ace3c 04999024      272    
total 0 objects
Statistics:
      MT    Count    TotalSize Class Name
04999024               2176 MyNamespace.MyType
Total 8 objects

This is how I do it. If anybody has better I would like to hear.


Posted Mar 09 2012, 05:46 AM by Damir Dobric
Filed under:
developers.de is a .Net Community Blog powered by daenet GmbH.