Reputation: 14060
Is it possible to check how many references are held to a given instance in .NET 3.5?
Upvotes: 1
Views: 1892
Reputation: 23731
This can be done using the WinDbg debugger if you load the SOS extension:
.loadby sos.dll mscorwks
You'll need to find the address of the object in memory, probably best done using the !dumpheap
command. With the object address, you can then run !gcroot <address>
to find all the references to your object.
Upvotes: 2
Reputation: 38464
You can not get this information at runtime via the CLR as reference counts are not maintained by the CLR. A big hint of this is that the Garbage Collector is generational and not reference count driven.
Raymond Chen has a good post on this topic here:
http://blogs.msdn.com/b/oldnewthing/archive/2010/08/11/10048629.aspx
Upvotes: 1
Reputation: 22701
While debugging, You can use Windbg to get this data. There are specific commands in Windbg. I am not an expert in Windbg but this would get you started
http://www.bytetalk.net/2009/03/windbg-tips-and-tricks.html
Upvotes: 1