Java SE API
SoftReference
Memory-sensitive retention subject to collector policy, not a strict cache bound.
Formal Syntax & Structure
java syntaxjava
new SoftReference<>(value)Working Example
Example Snippetjava
public class Main {
public static void main(String[] args) throws Exception { Object value = new Object(); var soft = new java.lang.ref.SoftReference<>(value); var phantom = new java.lang.ref.PhantomReference<>(value, new java.lang.ref.ReferenceQueue<>()); System.out.println(soft.get() == value); System.out.println(phantom.get() == null); java.lang.ref.Reference.reachabilityFence(value); }}