public class

OOMSoftReference

extends Object
java.lang.Object
   ↳ com.facebook.common.references.OOMSoftReference<T>

Class Overview

To eliminate the possibility of some of our objects causing an OutOfMemoryError when they are not used, we reference them via SoftReferences. What is a SoftReference? A Soft Reference is a reference that is cleared when its referent is not strongly reachable and there is memory pressure. SoftReferences as implemented by Dalvik blindly treat every second SoftReference as a WeakReference every time a garbage collection happens, - i.e. clear it unless there is something else referring to it: dalvik art It will however clear every SoftReference if we don't have enough memory to satisfy an allocation after a garbage collection. This means that as long as one of the soft references stays alive, they all stay alive. If we have two SoftReferences next to each other on the heap, both pointing to the same object, then we are guaranteed that neither will be cleared until we otherwise would have thrown an OutOfMemoryError. Since we can't strictly guarantee the location of objects on the heap, we use 3 just to be on the safe side. TLDR: It's a reference that's cleared if and only if we otherwise would have encountered an OOM.

Summary

Public Constructors
OOMSoftReference()
Public Methods
void clear()
T get()
void set(T hardReference)
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public OOMSoftReference ()

Public Methods

public void clear ()

public T get ()

public void set (T hardReference)