Debugging/Comparing Managed or .net memory dumps using Visual Studio 2013

Visual Studio 2013 comes with a new feature called “Debug Managed Memory” this feature also allows to compare managed memory usage across two dumps.  Read on…

This is how you would open a .net 4.5 memory dump in Visual Studio…

imageimage

So for the purpose of this blog I’ve created memory dumps of a managed application that consumes high memory: memtest.exe. I’ve collected three memory dumps…

  1. MemTest.dmp
  2. MemTest (2).dmp
  3. MemTest (3).dmp

For demo purpose I’m opening MemTest (3).dmp ‘first’ as shown in the above screenshot. So once you open the dump in Visual studio this is how Visual Studio will look like…

image

Check out mouse cursor location in the above screenshot. Click on this option. You’ll following dialog pop up….

image

Following which you’ll see the following screen…

image

This report will show the most number of objects on heap. If you notice the largest objects in my case are ArrayLists and second one is MemTest.Form1, too many forms. The also shows you the roots to an object.

Further in the above screenshot, I’ve highlighted an item in red. That option allows us to compare multiple dumps. The resultant report will show you the diff view between the two dumps. For demo I’m comparing MemTest (3).dmp with MemTest.dmp. MemTest (3).dmp was collected after  memtest.dmp was collected so you should ideally see a positive diff between the two dumps as the memory is increasing. See screenshot…

image

You’ll see that, new columns has been added to this report, for e.g. “Cound Diff.”, ‘Size Diff (Bytes)” etc. The bottom table shows you the “Reference Count Diff.” as well.

Really cool feature! Comparing managed memory has been never easier. Please note this feature is only enabled for.net memory dumps that use .net 4.5.

Appreciate your comments...