SOS Command: !GCRoot
!GCRoot [-nostacks] <Object address>
!GCRoot looks for references (or roots) to an object. These can exist in four places:
- On the stack
- Within a GC Handle
- In an object ready for finalization
- As a member of an object found in 1, 2 or 3 above.
First, all stacks will be searched for roots, then handle tables, and finally the freachable queue of the finalizer. Some caution about the stack roots: !GCRoot doesn’t attempt to determine if a stack root it encountered is valid or is old (discarded) data. You would have to use !CLRStack and !U to disassemble the frame that the local or argument value belongs to in order to determine if it is still in use.
Because people often want to restrict the search to gc handles and freachable objects, there is a -nostacks option.
Sample output:
!GCRoot 012c2c10 Note: Roots found on stacks may be false positives. Run "!help gcroot" for more info. Error during command: Warning. Extension is using a callback which Visual Studio does not implement. Scan Thread 580 OSTHread 244 ESP:12f05c:Root:012c2c10(System.Object[]) ESP:12f194:Root:012c2c10(System.Object[]) ESP:12f414:Root:012c2c10(System.Object[]) ESP:12f444:Root:012c2c10(System.Object[]) ESP:12f534:Root:012c2c10(System.Object[]) ESP:12f6e0:Root:012c2c10(System.Object[]) ESP:12f708:Root:012c2c10(System.Object[]) Scan Thread 3448 OSTHread d78 DOMAIN(0015D338):HANDLE(Strong):9111a8:Root:012c2c10(System.Object[])