Java Reference
In-Depth Information
ory and practice: Plugging memory leaks with weak references” ( ht-
index.html ) tutorials to be helpful in understanding the Reference API.
Basic Terminology
Whenanapplicationruns,itsexecutionrevealsa root set of references ,acollectionof
plication runs. For example, parameters disappear after a method returns.
determineifanobjectis reachable (referenced,alsoknownas live )or unreachable (not
collect objects that, starting from the root set of references, cannot be reached.
Note Reachable objects include objects that are indirectly reachable from root-set
variables, which means objects that are reachable through live objects that are direc-
root-set variable is eligible for garbage collection.
softly, weakly, and phantom reachable objects can be garbage collected.
Going from strongest to weakest, the different levels of reachability reflect the life
cycle of an object. They are defined as follows:
• Anobjectis strongly reachable ifitcanbereachedfromsomethreadwithout
traversingany Reference objects.Anewlycreatedobject(suchastheobject
referencedby d in Double d = new Double(1.0); )isstronglyreach-
able by the thread that created it. (I will discuss threads later in this chapter.)
• An object is softly reachable if it is not strongly reachable but can be reached
by traversing a soft reference (a reference to the object where the reference is
storedina SoftReference object).Thestrongestreferencetothisobjectisa
the object becomes eligible for finalization (discussed in Chapter 2 ) .
• Anobjectis weakly reachable ifitisneitherstronglyreachablenorsoftlyreach-
able,butcanbereachedbytraversinga weak reference (areferencetotheob-
jectwherethereferenceisstoredina WeakReference object).Thestrongest
Search WWH ::

Custom Search