During development phase of my current project I try to figure out if my application has memory leaks. The client where I am working prevent me from installing software on my development computer. I don’t have installed Microsoft Windows SDK, so I cannot use WinDBG. This article is a quick post to introduce Visual Studio 2010 and sos.dll
Before starting your application, on the project properties> Debug tab, make sure that “Enable unmanaged code debugging” is enabled.
Start your debugging your application, execute the scenario where you found that there is a memory leak, break at the end of this execution (Break All or CTRL+ALT+DEL).
In Visual Studio, Open the immediate windows and load sos.dll.
For .net 4.0 application:
For .net 2.0, 3.0 or 3.5 application:
Enter the following command line to get the summary of object types that are still in memory:
If one of the type should not be in memory, you can filter for a specific type:
!dump –type MyNamespace.MyType
This lists all objects of this specific type in the heap. Once you have the address of one specific object you can get a dump of a specific object:
This dump lists all the objects that references, and that forces the object to be kept in the heap. After you should investigate deeper
Main commands to use
|Summary of classes|
|MyNamespace.MyType||Lists all objects in the heap of this specific type|
|Returns the ump of a specific object|
MSDN reference : http://msdn.microsoft.com/fr-fr/library/bb190764.aspx
Tess Ferrandez blog: http://blogs.msdn.com/b/tess/ (very interesting blog). She wrote several good post but also one dedicated on “Debugging Silverlight applications with windbg and sos.dll”