Objects in a heap dump have references to other objects. These can either be
via field references (for simple objects), array elements (for object arrays)
or via various hidden references. For instance every object contains a reference to
its type, and each class contain a reference to the class loader which loaded
the class.
These objects and references form a directed graph. The objects are the nodes,
the references are the directed links between the nodes. The
garbage collection roots are the roots of this graph.
- Reachable
- An object is reachable from another object if there is a
path following the directed links from the source object to the destination object.
- Unreachable object
- If there is no path from a garbage collection root
to an object then it is unreachable. There is then no way a legitimate Java program
can every get access to this object, so it is safe for the Java virtual machine to
discard this object from the heap. This process of determining unreachable objects and
discarding them, thus making room for more objects to be allocated as required, is
called garbage collection.