Inspecting Objects using WinDbg

As I was trying to figure out a source of memory leaks in a Silverlight application, I encountered a need to closely inspect an object.  WinDbg has a command that you can use drill down into an object hierarchy, and even inspect primitive and complex properties of an object.  If you read my previous blog entries, you already know how to load WinDbg and attach it to a process.  Once that is done, you can use !dumpheap command to look at each object and !dumpheap -MT to look at the instances of each type.  Once you get an object address from the output of !dumpheap -MT command, you can then type

!dumpobj XXXX

where XXXX is the object address.

The output will list the properties of the object you are inspecting along with handles for each property.  Then you can continue repeating the !dumpobj command and drill as deep as you need to into object/property hierarchy.  You can use Value column from !dumpobj output to drill in, using this value as a parameter to the next !dumpobj command.  For simple properties, such as strings you will see sting values.  This can be extremely useful if you have multiple instances of an object, and only some leak based on some property values.

Enjoy.  You can find other blog entries on use of WinDbg by searching this blog with WinDbg as search parameter.


Leave a Reply

Your email address will not be published. Required fields are marked *