More Memory Leak Troubleshooting

Recently, I have been doing a lot of Memory troubleshooting.

Here are some windbg commands that helped:

Load the sos module (for .Net 4.0)

.loadby sos clr

List all of my object specific to my program:

!dumpheap -stat -type <parent namespace>

List all the instances of a particular object:

!dumpheap -type <namespace>.<object class name>

List references to the object:

!gcroot <address>

Break on garbage collection:

!findroots gen any

List references to the obect (must break in garbage collection):

!findroots <address>

Show sizes in the memory:


List large strings in memory:

!dumpheap -type System.String -min 10000

Then, I also found that you can use the SOS module with within Visual Studio.  First, in the project settings, I had to go to the Debug tab and check “Enable unmanaged code debugging” under “Enable Debuggers”.  Then, in the immediate window, I could run the following command:

.load sos

I thought my problem seemed to be related to the Data Grid view just like this forum post.  The post lists a code fix, but my problem is finding out where I place the code.  This blog mentions putting the code in the Form Close, but my problem is during the execution of the program.

Actually, it ended up being that I was loading a hidden column into the grid that was taking a lot of memory.  I had a Select * SQL statement, and I had to list only the fields that I wanted in memory.


UserPreferenceChangedEventHandler Resources

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.