�reachable� is a Very important
word in the context of garbage collection. It is worth getting the best explanation you can find.
1A. The
Java virtual machine uses garbage collection to ensure that any referenced object will remain in memory, and to free up memory by deallocating objects that are no longer reachable from references in executing code. This is a strong guarantee--an object will not be collected if it can be reached by following a chain of references starting with a *root* reference, that is, a reference that is directly accessible from executing code.
(That�s a lot of words. They are all important. Read this several times.)
1B. An object is �no longer reachable� when no reference to the object exists in any variable of any currently executing method, nor can you find a reference to the object starting from such variables and then following each field or array element, and so on.
(Same author repeating himself in the next paragraph. The only thing missing is you can also start from references in static variables.)
2A. An object enters an *unreachable* state when no more strong references to it exist. When an object is unreachable, it is a *candidate* for collection.
2B. It is important to note that not just any strong reference will hold an object in memory. These must be references that chain from a garbage collection root. GC roots are a special class of variable that includes temporary variables on the stack (of any
thread), static variables (from any class) and special references from JNI native code.
(Try to imagine the garbage collection roots and the chain of references.)
My references are The Java Programming Language 12.1 and The Truth About Garbage Collection
The Truth [ June 17, 2003: Message edited by: Marlene Miller ]