Previous | Next | Trail Map | Reference Objects | All About Reference Objects

Chains of Reference Objects

A given path to an object can contain more than one kind of reference object, which creates a chain of reference objects. The garbage collector processes reference objects in order from strongest to weakest. The processing always happens in the following order, but there is no guarantee when the processing will occur: In the diagram below, there is a chain of reference objects to Some Object. When the garbage collector processes the reference objects, will it find Some Object to be phantomly, weakly, or softly reachable?

The answer is Some object is phantomly reachable. In general, an object is only as reachable as the weakest link in the strongest path from the root set. In the diagram, the phantom reference is strongly reachable, but all other objects are phantomly reachable.

However, if Weak reference is strongly reachable as shown in the next diagram, both Phantom reference and Weak reference are strongly reachable, and Soft reference and Some object are weakly reachable.

Can you guess what happens if Soft reference is strongly reachable?
The answer is Phantom reference, Weak reference, and Soft reference are strongly reachable, and Some Object is softly reachable.


Previous | Next | Trail Map | Reference Objects | All About Reference Objects