Java.Lang.Ref.SoftReference Class
A reference that is cleared when its referent is not strongly reachable and there is memory pressure.

See Also: SoftReference Members

Syntax

[Android.Runtime.Register("java/lang/ref/SoftReference", DoNotGenerateAcw=true)]
public class SoftReference : Reference

Remarks

A reference that is cleared when its referent is not strongly reachable and there is memory pressure.

Avoid Soft References for Caching

In practice, soft references are inefficient for caching. The runtime doesn't have enough information on which references to clear and which to keep. Most fatally, it doesn't know what to do when given the choice between clearing a soft reference and growing the heap.

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.

Garbage Collection of Soft References

When the garbage collector encounters an object obj that is softly-reachable, the following happens: The system may delay clearing and enqueueing soft references, yet all SoftReferences pointing to softly reachable objects will be cleared before the runtime throws an Java.Lang.OutOfMemoryError.

Unlike a WeakReference, a SoftReference will not be cleared and enqueued until the runtime must reclaim memory to satisfy an allocation.

[Android Documentation]

Requirements

Namespace: Java.Lang.Ref
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1