John C. Bollinger said:
An object automatically becomes eligible for garbage collection when it
ceases to be reachable from any live thread via a chain of strong
(normal) references. That is the only criterion.
Since we seem to be in the mood to talk about garbage collection a lot,
here is the full story.
Garbage collection theorists (at least, those who are picky about words)
distinguish between these concepts:
An object is LIVE if the program will access it at some point in the
future. An ideal garbage collector would collect all objects that
are not live. However, such a garbage collector is impossible in
the general case. It would need to know all future actions of the
user in advance, for example. Some kind of ESP would be needed.
An object is ACTIVE is some possible future execution of the current
application could potentially access it. Active objects form a
superset of live objects. This category has the advantage that,
unlike liveness, it can be determined without any ability to predict
the future.
An object is REACHABLE if there is any path to reach it through
variables that are lexically in scope (regardless of accessibility)
from the root set. This is a superset of active objects. It has
the advantage that it is much easier to determine than activeness.
Garbage collectors fall into several kinds:
Collectors that cannot collect even all unreachable objects are known as
"conservative", whereas garbage collectors that collect all unreachable
objects are "precise".
Garbage collectors that even collect some reachable but inactive objects
aren't given an adjective, but are said to be doing "liveness analysis".
The word is applied regardless of whether all inactive objects are
collected, or just some. This is an odd term when you consider that
what's really happening is more like activeness analysis, but
nevertheless the word stuck. Modern garbage collection work is less
concerned with preserving the meaning of the word "live", since strict
liveness is a completely useless concept. Liveness analysis is still
immensely difficult in the general case; global liveness analysis is
practically never done. Local liveness analysis, though, is somewhat
common.
Garbage collectors that collect some active objects are called "broken",
and are generally called that in an angry voice.
As for Java, Dale King and I have often argued about whether the Java
specification allows Java to collect only unreachable objects, or also
inactive objects as well. I believe the latter to be the case; in fact,
I think the spec is crystal clear on the matter; but Dale disagrees.
Search Google groups for more on this one, if you're interested.
--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation