Reachability

If, at some moment of the application run,
the root object stops referencing an allocated object,
the object becomes unreachable,
which is a signal for the garbage collector (GC)
to deallocate the object’s memory.

Retaining path

The sequence of references from root to an object
is called the object’s retaining path,
as it retains the object’s memory from the garbage collection.
One object can have many retaining paths.
Objects with at least one retaining path are
called reachable objects.

Example

The following example illustrates the concepts:

class

Child

{}

class

Parent

Child

child

Parent

parent1

Parent

();

void

myFunction

()

Child