Middle
What are Garbage Collector Roots?
sobes.tech AI
Answer from AI
Garbage Collector Roots are objects or references from which the traversal of memory begins to determine the reachability of objects in the heap.
GC Roots include:
- Local variables and parameters of current threads (call stack).
- Static fields of classes.
- Active threads.
- Objects registered in native code (e.g., via JNI).
The garbage collector starts from these roots and recursively marks all reachable objects. Objects that are unreachable from the roots are considered garbage and are eligible for removal.
This is a key mechanism for efficient memory management in JVM and Android, allowing automatic freeing of unused objects.