Tracking down managed memory leaks
Steps to track managed memory leaks
Simple Steps
Very Simple:
1. Debug your code from VS and run.
2. When app is stable, from VS break all (or pause)
3. Now open “Immediate window”
4. Type following to load sos.dll
.load C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\sos.dll
5. Then type
!DumpHeap –type
2. When app is stable, from VS break all (or pause)
3. Now open “Immediate window”
4. Type following to load sos.dll
.load C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\sos.dll
5. Then type
!DumpHeap –type
For Ex:
!DumpHeap -type SomeNameSpace.ClassNameObj
!DumpHeap -type SomeNameSpace.ClassNameObj
Above command will give reference counts of specified type, along with the address of each reference.
7 Then you can use: !gcroot
For Ex: !gcroot 02bcddc8
For Ex: !gcroot 02bcddc8
This will give the reachable reference path that is holding your reference. Check for HANDLE(Pinned) in above result. This specifies the non collectible references. Others with HANDLE(WeakSh) or HANDLE(WeakLn) are weak short and weak long references that can be collected by garbage collector.
Comments
Post a Comment