palm snow
palm snow

Reputation: 2392

Which thread is using a given object?

  1. I run dumpheap -type MyObjectType command to get the method table for MyObjectType. It shows three object on heap.
  2. I run dumpheap -mt <method table address> to get address.
  3. I run !gcroot <address> command to find the references to these objects, find nothing
  4. !do <address> and it provides details about fields for this object etc.

How can I find which thread is referencing or using object? Any command to find that out?

Upvotes: 1

Views: 784

Answers (2)

Brian Rasmussen
Brian Rasmussen

Reputation: 116431

There's no easy way to do this, but you could run !dso for each thread (i.e. ~*!dso). That will tell you which objects each of the threads reference. To help navigate the output I usually log it to a file and use grep or a decent text editor to search the results.

Upvotes: 1

user418938
user418938

Reputation:

You might try to use Microsoft's CLR Profiler to find out which thread allocated and accessed your object. I'm not sure if !gcroot shows objects waiting for finalizer, but CLR Profiler definitely does. Your object also might be not referenced from any GC root at all and it's just waiting for collection to occur. It can take quite some time especially if it is allocated in LOB heap. Try forcing a few GCs (and see if gen0-2 collections actually took place) and see if your object survives.

Upvotes: 0

Related Questions