GC finds reachable objects
Garbage consists of objects the program can no longer access through references.
The garbage collector (GC) starts from the roots and follows references. The objects it finds are still accessible to the program, so it retains them. Memory occupied by the remaining objects can be released.
The example contains the chain root → scene → player. These objects are accessible only through the connections shown.
The buttons replace a reference with null:
- Scene → player: the player becomes unreachable; the scene remains accessible.
- Root → scene: both objects become unreachable.