Class java.lang.ref.SoftReference
java.lang.Object
|
+--java.lang.ref.Reference
|
+--java.lang.ref.SoftReference
- public class SoftReference
- extends Reference
Soft reference objects, which are cleared at the discretion of the garbage
collector in order to release memory for reclamation.
If the garbage collector determines at a certain point in time that an
object is no longer strongly reachable, then at that time it may choose to
clear all soft references to the object in order to release the memory that
it occupies for reuse. If a soft reference is registered with a reference
queue, then it will be enqueued some time after it is cleared.
All soft references to softly-reachable objects are guaranteed to have
been cleared before the virtual machine throws an OutOfMemoryError.
Otherwise no constraints are placed upon the time at which a soft reference
will be cleared or the order in which a set of such references will be
cleared. Virtual machine implementations are, however, encouraged to bias
against clearing recently created or recently used soft references.
Direct instances of this class may be used to implement simple caches;
this class or derived subclasses may also be used in larger data structures
to implement more sophisticated caches. As long as the referent of a soft
reference is strongly reachable, that is, is actually in use, the soft
reference will not be cleared. Thus a sophisticated cache can, for example,
prevent its most recently used entries from being discarded by keeping
strong referents to those entries, leaving the remaining entries to be
discarded at the discretion of the garbage collector.
- Since:
- JDK1.2
- See Also:
Reference
Constructor Summary
|
SoftReference(Object referent,
ReferenceQueue q)
Create a new soft reference that refers to the given object and is
registered with the given queue. |
SoftReference(Object referent)
Create a new soft reference that refers to the given object. |
Method Summary
|
Object
|
get()
Return the object to which this reference object refers. |
Methods inherited from class java.lang.Object |
clone
, equals
, finalize
, getClass
, hashCode
, notify
, notifyAll
, toString
, wait
, wait
, wait
|
SoftReference
public SoftReference(Object referent)
- Create a new soft reference that refers to the given object. The new
reference is not registered with any queue.
SoftReference
public SoftReference(Object referent,
ReferenceQueue q)
- Create a new soft reference that refers to the given object and is
registered with the given queue.
- Throws:
- NullPointerException - If the
queue
argument
is null
get
public Object get()
- Return the object to which this reference object refers. If this
reference has been cleared, either by the program or by the garbage
collector, then return
null
.
- Overrides:
- get in class Reference
Submit a bug or feature
Submit comments/suggestions about new javadoc look
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.
This documentation was generated with a post-Beta4 version of Javadoc.