mgamer
mgamer

Reputation: 14060

Check how many references are held to a given instance in .NET 3.5

Is it possible to check how many references are held to a given instance in .NET 3.5?

Upvotes: 1

Views: 1892

Answers (5)

Iridium
Iridium

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

Tim Lloyd
Tim Lloyd

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

Uwe Keim
Uwe Keim

Reputation: 40736

I love ANTS Memory Profiler for those kind of tasks.

Upvotes: 1

Madhur Ahuja
Madhur Ahuja

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

SLaks
SLaks

Reputation: 887767

You cannot do this at runtime.

Upvotes: 4

Related Questions