Thursday, January 12, 2017

.NET debugging Lab1: Inspect managed heap using WinDBG commands !EEHeap -gc and !heapstat


Aim :  Learn to execute two WinDBG commands

1. !EEHeap -gc
2. !heapstat

Related Concepts

We have learned that .NET Managed heap has parted into Three heap regions (Generation 0,1,2) .

 Lets observe these generational heap regions existing on .NET application using a debugging session.


Prerequisites for this demo

1. The dump file (23 MB) for this demo available Here 

2. Download dump file, unzip the file.

Our suggestion : We have made a short video explaining below demo steps.

Here is the video link :  Video


Step-by-step instructions for this demo

1. Download dump file, unzip the file.
2. Start WinDBG (x86 version)
3. Open File Menu => Open Crash dump
















4. Select the dump file "Demo1_PrintManagedHeap.dmp" . Apply OK
     (The dump file loaded to debugger. )

5. Apply command to load SOS.dll . [Image given below ]
     (SOS dll contains all .NET debugging commands. So this is a preliminary step prior to every .NET application debugging using WinDBG)













6. Apply command !eeheap -gc on the prompt [Result provided below]

   In this result user can observe,

     a) The Total GC heap size (pointed by red arrow)
     b) We can also see the Generation heap regions and their starting point
     c) The result also shows Large object heap ( a special managed heap region to store
         large objects


7. From the above command, we printed the managed heap information. But we have not got the size of each generational heap . There is one more command that helps to print that result.

apply !heapstat    [image given below]

      a) observe the memory allocation size of each region (Gen 0,Gen1,Gen 2) and LOH is provided


Summary

In this demo we have learned two new windows debugging commands for printing the .NET managed memory information. Also , we have learned about Generational heap regions theoretically and now we saw them and their sizes via a debugging session.

In the next session, we will come up with a new .NET CLR concept and new debugging commands.

We request users to Subscribe to our YouTube channel for receiving .NET debugging tutorial videos (top right side button)

.Net Debugging Lab3 : Inspect Compacting the Heaps using WinDBG commands: - !heapstat

Related .NET internals: 1.        Gen 0 and Gen 1 are compacting heap regions :   When Garbage collector (GC) operates on a Gen 0 or ...