java.lang.Object | ||
↳ | java.lang.ref.Reference <T> | |
↳ | java.lang.ref.SoftReference<T> |
A reference that is cleared when its referent is not strongly reachable and there is memory pressure.
The lack of information on the value to your application of each reference limits the usefulness of soft references. References that are cleared too early cause unnecessary work; those that are cleared too late waste memory.
Most applications should use an
android.util.LruCache
instead of
soft references. LruCache has an effective eviction policy and lets the user
tune how much memory is allotted.
obj
that is
softly-reachable, the following happens:
refs
of references is determined.
refs
contains
the following elements:
obj
.
obj
is
strongly reachable.
refs
are atomically cleared.
refs
will be enqueued with their corresponding reference queues, if
any.
SoftReference
s pointing to softly reachable objects will be cleared before
the runtime throws an
OutOfMemoryError
.
Unlike a
WeakReference
, a
SoftReference
will not be
cleared and enqueued until the runtime must reclaim memory to satisfy an
allocation.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Constructs a new soft reference to the given referent.
|
||||||||||
|
Constructs a new soft reference to the given referent.
|
[Expand]
Inherited Methods
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.ref.Reference
|
|||||||||||
From class
java.lang.Object
|
Constructs a new soft reference to the given referent. The newly created reference is not registered with any reference queue.
r | the referent to track |
---|
Constructs a new soft reference to the given referent. The newly created reference is registered with the given reference queue.
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. |