java.lang.ref

Class 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.
Constructor Summary
SoftReference(T referent)
Create a new soft reference, that is not registered to any queue.
SoftReference(T referent, ReferenceQueue<? super T> q)
Create a new soft reference.
Method Summary
Tget()
Returns the object, this reference refers to.

Constructor Detail

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.

Method Detail

get

public T get()
Returns the object, this reference refers to.

Returns: the object, this reference refers to, or null if the reference was cleared.