dotMemory
 
2021.1
You are viewing the documentation for an earlier version of dotMemory.

Analyze GC Roots

Last modified: 08 March 2021

Retention path of an object always starts with a GC root. From the point of Garbage Collector, root is a reference to an object that must not and will not be collected. This makes roots the only possible starting point for building retention graphs. Understanding root types can be extremely important during the "Who retains the object?" analysis. Sometimes examining retention paths does not give you an answer why the object is still in memory. In this case, it makes sense to look at GC roots. For example, a RefCounted handle gives you a clue that the object is retained by some unmanaged COM library.

There are four possible root types in .NET Framework:

  • Stack references: references to local objects. Such roots live during a method execution.

  • Static references: references to static objects. These roots live the entire app domain life time.

  • Handles: typically, these are references used for communication between managed and unmanaged code. Such roots must live at least until the unmanaged code needs "managed" objects.

  • Finalizer references: references to objects waiting to be finalized. These roots live until the finalizer is run.

To analyze a root of a retention path, use any dotMemory view that shows object retention paths: Group by Similar Retention, Group by Shortest Paths, Key Retention Paths, and Shortest Paths to Roots. Note that all root types distinguished by dotMemory fall into one of the categories mentioned int the list above.