|
JavaTM 2 Platform Std. Ed. v1.4.2 |
||||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
See:
Description
Class Summary | |
PhantomReference | Phantom reference objects, which are enqueued after the collector determines that their referents may otherwise be reclaimed. |
Reference | Abstract base class for reference objects. |
ReferenceQueue | Reference queues, to which registered reference objects are appended by the garbage collector after the appropriate reachability changes are detected. |
SoftReference | Soft reference objects, which are cleared at the discretion of the garbage collector in response to memory demand. |
WeakReference | Weak reference objects, which do not prevent their referents from being made finalizable, finalized, and then reclaimed. |
Provides reference-object classes, which support a limited degree of interaction with the garbage collector. A program may use a reference object to maintain a reference to some other object in such a way that the latter object may still be reclaimed by the collector. A program may also arrange to be notified some time after the collector has determined that the reachability of a given object has changed.
Each reference-object type is implemented by a subclass of the abstract
base
class. An instance of one of
these subclasses encapsulates a single reference to a particular object, called
the referent. Every reference object provides methods for getting and
clearing the reference. Aside from the clearing operation reference objects
are otherwise immutable, so no Reference
set
operation is provided. A
program may further subclass these subclasses, adding whatever fields and
methods are required for its purposes, or it may use these subclasses without
change.
ReferenceQueue
class.
The relationship between a registered reference object and its queue is one-sided. That is, a queue does not keep track of the references that are registered with it. If a registered reference becomes unreachable itself, then it will never be enqueued. It is the responsibility of the program using reference objects to ensure that the objects remain reachable for as long as the program is interested in their referents.
While some programs will choose to dedicate a thread to removing reference
objects from one or more queues and processing them, this is by no means
necessary. A tactic that often works well is to examine a reference queue in
the course of performing some other fairly-frequent action. For example, a
hashtable that uses weak references to implement weak keys could poll its
reference queue each time the table is accessed. This is how the
class works. Because the WeakHashMap
method simply
checks an internal data structure, this check will add little overhead to the
hashtable access methods.
ReferenceQueue.poll
|
JavaTM 2 Platform Std. Ed. v1.4.2 |
||||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
Copyright 2003 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.