Sobes.tech
Junior — Middle

Can you name the main types of root objects used in the garbage collector?

sobes.tech AI

Answer from AI

In the Android garbage collector (based on JVM), the main root objects (roots) from which the traversal begins to identify reachable objects are:

  • Stack roots — local variables and method parameters in the current active stack frames.
  • Static roots — static class variables available during runtime.
  • Processor registers — values stored in CPU registers that may contain references to objects.
  • JNI References — references created through Java Native Interface that can keep objects alive.

All objects reachable from these root objects are considered alive and are not subject to garbage collection. This allows the garbage collector to efficiently free memory by removing only unreachable objects.