After running the VS2010 profiler with Object Lifetime Tracking in my app, I have this on a particular class :
Number of Instances----------
EDIT 2018: if you have visual studio 2015+ then the whole process is much simpler: MSDN tutorial.
if you want to know exactly which instances are alive , all you need to do is take a process dump with Adplus, that comes with the debugging tools for windows. (its now part of the SDK download.)
then in WinDBG, use the !dumpheap -type command to see what instaces of which classes are still up.
then you can use the !gcroot to see who is holding that reference.
.load sos
!DumpHeap -type <partial type name>
This will return something like:
Address MT Size
026407c0 53ecee20 16
Then you can take the Address
and use GCRoot
to find the where it's rooted:
!GCRoot 026407c0
Chris Lovett (via Tess Ferrandez) created a very neat utility that converts the low-level GCRoot
output into a DGML graph which might make it easier to diagnose.
Alternatively, Mohamed Mahmoud created a debugger extension that enables you generate the graph from WinDBG, but it doesn't work within Visual Studio so you might want to stick to Chris's utility to avoid installing the Debugging Tools.
Having said that, the textual output may well be enough for you to track things down. If you want information on the output of GCRoot, type !help GCRoot
in the immediate window.
You can type the command gcroot
.