R – How to debug .net Garbage Collection


Is it possible to have a look at all .net objects which are collected upon calling GC.Collect()?

I need to see what objects are still in memory and not reclaimed, so I can find where reclaiming the objects should have done manual, but was forgotten by the programmer.
I don't want to call GC.Collect because someone somewhere forgot to dispose an object which blocks some handles.

Best Solution

I've found the best way to do this is to use windbg and the SOS (son of strike) extension. It has a rather cryptic command line but it is very powerful. It has the capability to dump the heap and divide it by the GC generational heap. Once you get past the initial learning curve, it's very easy to track what objects are alive in what portion of the heap. Here are a few web sites with examples of using SOS

EDIT OP asked about the location of sos.dll. It is included with the install of the .Net Framework. It is located at


But once you have windbg loaded you don't need the full path. Just us the .loadby method.

.loadby sos mscorwks.dll

It will look for the version of sos in the same directory as the current version of mscorwks (the CLR)