Android
java.lang.ref
public class

java.lang.ref.SoftReference<T>

java.lang.Object
java.lang.ref.Reference<T>
java.lang.ref.SoftReference<T>

Implements a soft reference, which is the least-weak of the three types of references. Once the garbage collector has decided that an object obj is ref of references is determined. ref contains the following elements:

  • All references in ref are atomically cleared.
  • At the same time or some time in the future, all references in ref will be enqueued with their corresponding reference queues, if any.
  • The system may decide not to clear and enqueue soft references until a later time, yet all SoftReferences pointing to softly reachable objects are guaranteed to be cleared before the VM will throw an
    OutOfMemoryError. Soft references are useful for caches that should automatically have their entries removed once they are not referenced any more (from outside), and there is a need for memory. The difference between a SoftReference and a WeakReference is the point of time at which the decision is made to clear and enqueue the reference:
    • A SoftReference should be cleared and enqueued as late as possible, that is, in case the VM is in danger of running out of memory.
    • A WeakReference may be cleared and enqueued as soon as is known to be weakly-referenced.

    Summary

    Public Constructors

                SoftReference(T r)
    Constructs a new soft reference to the given referent.
                SoftReference(T r, ReferenceQueue<? super T> q)
    Constructs a new soft reference to the given referent.
    Methods inherited from class java.lang.ref.Reference
    Methods inherited from class java.lang.Object

    Details

    Public Constructors

    public SoftReference(T r)

    Constructs a new soft reference to the given referent. The newly created reference is not registered with any reference queue.

    Parameters

    r the referent to track

    public SoftReference(T r, ReferenceQueue<? super T> q)

    Constructs a new soft reference to the given referent. The newly created reference is registered with the given reference queue.

    Parameters

    r the referent to track
    q the queue to register to the reference object with. A null value results in a weak reference that is not associated with any queue.
    Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56