When we search leak memory in our application, we use SOS.dll in Windbg.exe or Visual studio IDE.
This tool is very very usefull but it is not easy to walk accross the references tree of object.
Visual Studio is more powerfull to do that. “Quick watch window” for example with its property explorator is perfect.
but “sos command’s” returns only addresses of objects …
Evaluate an object in VS from GCHandle address
!GCRoot give often this type of informations :
!GCRoot -nostacks 00c58918
If you evaluate this in VS debugger :
You found the instance of System.Threading.Thread (address 00c21b30) !!
Find address object in Quick watch windows …
It is possible to fix the memory area of an object with System.Runtime.InteropServices.GCHandle object. When you create a GCHandle on a object with GCHandleType.Pinned option. GCHandle.AddrOfPinnedObject() return the memory location of it !
BUT it is possible to use internal method to give the current address of object even if this object is not pinned
If you evaluate this, in “Quick Watch window” of VS, or in “Immediat window” :
The result give the same address of myObjectSomeWhere in SOS commands Like
If you know where the object is in your application, you can find the address of it, and compare with SOS Commands results.
Evaluate object in VS from directly address
It would be very usefull to evaluate, for example, 00d0b0dc EventHandler instance in VS debugger !
BUT I did not found a tips to do this … directly, sorry … :-(
This reference http://stackoverflow.com/questions/3141428/conversion-from-void-to-object-in-c asks the same question without answer …
If I would find it, I will be able to update this post !
- Memory explanations about .Net Value and reference types : http://www.codeproject.com/KB/cs/net_type_internals.aspx
- Explanations about GCHandle and differences between GCHandle.AddrOfPinnedObject et GCHandle.ToIntPtr : http://blogs.msdn.com/b/jmstall/archive/2006/10/09/gchandle_5f00_intptr.aspx
- SOS.DLL microsoft documentation : http://msdn.microsoft.com/fr-fr/library/bb190764.aspx