java.lang.ref
Class SoftReference<T>
java.lang.Object
java.lang.ref.Reference<T>
java.lang.ref.SoftReference<T>
public class SoftReference<T>
- extends Reference<T>
A soft reference will be cleared, if the object is only softly
reachable and the garbage collection needs more memory. The garbage
collection will use an intelligent strategy to determine which soft
references it should clear. This makes a soft reference ideal for
caches.
Method Summary |
T |
get()
Returns the object, this reference refers to. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SoftReference
public SoftReference(T referent)
- Create a new soft reference, that is not registered to any queue.
- Parameters:
referent
- the object we refer to.
SoftReference
public SoftReference(T referent,
ReferenceQueue<? super T> q)
- Create a new soft reference.
- Parameters:
referent
- the object we refer to.q
- the reference queue to register on.
- Throws:
NullPointerException
- if q is null.
get
public T get()
- Returns the object, this reference refers to.
- Overrides:
get
in class Reference<T>
- Returns:
- the object, this reference refers to, or null if the
reference was cleared.