Sobes.tech
Middle+

What are GC roots? What types are there?

sobes.tech AI

Answer from AI

GC roots (garbage collector roots) are objects or references that are considered entry points for the garbage collection algorithm in .NET. The garbage collector starts traversing objects from these roots to determine which objects are alive and should remain in memory.

Typical GC roots in .NET:

  • Local variables and parameters of current threads (call stack).
  • Static fields of classes.
  • Objects registered via GCHandle with type Pinned.
  • Objects used in managed code through COM interop.
  • Objects associated with active delegates and events.

All objects reachable from these roots are considered alive; others are candidates for removal.

What are GC roots? What types are there? — C# - sobes.tech