SoftReference

The SoftReference class describes a Reference object whose referent is softly reachable.

SoftReference is useful for caching objects that are expensive timewise to create and/or occupy significant amounts of heap space.

 
import java.lang.ref.SoftReference;

public class Main {
  public static void main(String[] args) {
    Integer integer = Integer.parseInt("0");
    System.out.println("caching Integer");
    SoftReference<Integer> cache = new SoftReference<Integer>(integer);
    integer = null;
    
    if(cache.get() != null) {
      System.out.println("Integer is still cached");

    }
  }
}
  
Home 
  Java Book 
    Language Basics  

Reference:
  1. Reference
  2. SoftReference
  3. WeakReference
  4. PhantomReference