Class java.lang.ref.SoftReference
java.lang.Object
|
+----java.lang.ref.Reference
|
+----java.lang.ref.SoftReference
- public class SoftReference
- extends Reference
Soft reference objects, for use in implementing caches.
As the amount of memory available to the Java heap decreases, an
instance of this class may be cleared automatically if its referent is
reachable only via soft references and, perhaps, via some guarded, weak, or
phantom references. Soft references are cleared in approximate
least-recently-used order. A best effort is made to clear all soft
references before the virtual machine throws an
OutOfMemoryError
.
- Since:
- JDK1.2
- See Also:
- Runtime.MemoryAdvice
Constructor Summary
|
SoftReference(Object referent)
Construct a new soft reference that refers to the given object.
|
SoftReference(Object referent,
ReferenceQueue queue)
Construct a new soft reference that refers to the given object and is
registered with the given queue.
|
Method Summary
|
void
|
clear()
Clear this soft reference.
|
Object
|
get()
Return the object to which this soft reference refers, or
null if the reference has been cleared by the garbage
collector due to lack of memory.
|
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SoftReference
public SoftReference(Object referent)
- Construct a new soft reference that refers to the given object.
SoftReference
public SoftReference(Object referent,
ReferenceQueue queue)
- Construct 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 soft reference refers, or
null
if the reference has been cleared by the garbage
collector due to lack of memory.
Implementation note: This method may allocate a small object
and adjust an internal data structure, so it is not quite as fast as the
get
methods of the other Reference
types.
- Overrides:
- get in class Reference
clear
public void clear()
- Clear this soft reference.
- Overrides:
- clear 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.