Thanks to the good people at ShinyStat that provides me with free statistics of my blog, I am able to see all referrers including those that come from search engines and even see the keywords they have used to search and find this blog.

I’ve looked just now at the statistics and saw one combination of keywords that interested me. It was something like this: “!dumpheap parameters”

This means that someone was looking for some help on the parameters of the !dumpheap command, so I thought I’ll add some i.nformation about that.

What is !dumpheap?

!dumpheap is a command from the SOS extension that dumps the content of the managed heap.
You can get all the addresses and some additional information (as we will see) on all managed objects currently alive on the heap.

From the last two versions of WinDbg SOS was actually replaced by PSSCOR which has a good help system. For most commands you can simply type “!help commandName“, for example, “!help dumpheap” and you will get a details help on the parameters and how to use.

!dumpheap Parameters:

  • -stat – Outputs only the statistical summary of all types of objects on the heap, their count and their own size (without references)
  • -nostrings – Exclude the output of strings (when not using -stat).
  • -gen X – Outputs only objects that belong to generation X where X can have the following values: for 1.1 – 0, 1, 2 and 3 for large objects (objects larger than 85Kb without their references). For 1.0 everything expect use -1 instead of 3.
  • -min X – Ignores objects that are less than X (where X is a number in bytes).
  • -max X – Ignores objects that are larger than X (where X is a number in bytes).
  • -mt MethodTable – List only those objects with the MethodTable given.
  • -type TYPE – List only those objects whose type name is a substring math of TYPE.
  • -cache – Saves the objects in an internal cache for later use (helps to speed up things instead of rescanning the heap all over again).
  • -l X – Prints out only X items from each heap instead of all the objects.
  • -short – Prints out only the object address. Useful for combining with the .foreach command.
  • -fix START END – Use the given START and END addresses and scan the heap only between these addresses.

NOTE: If I remember correctly, -cache, -nostring and -short are all new commands that were added in the last two versions of SOS (previously PSSCOR), the rest are available for quite a while in most versions of SOS.

-short, the wonder parameter

Just to show you how powerful the -short option is, let say that you want to print the content of all gen 2 objects that you currently have. Prior to the -short command you had to run “!dumpheap -gen 2” copy the output to notepad, parse it to leave only object addresses and only then you could either run manually !do on each address, or use .foreach with the /f command.

Today, with -short all you need to do is run the following command line:
.foreach ( obj { !dumpheap -gen 2 -short } ) { !do ${obj} }

Quite useful, isn’t it…