A soft reference holds onto its referent until memory becomes low. : SoftReference « Reflection « Java Tutorial






import java.lang.ref.SoftReference;

public class Main {
  public static void main(String[] argv) throws Exception {
    SoftReference<String> sr = new SoftReference<String>("object");

    Object o = sr.get();
    if (o != null) {
      System.out.println(o);
    } else {
      System.out.println("collected or has been reclaimed");
    }
  }
}








7.16.SoftReference
7.16.1.A soft reference holds onto its referent until memory becomes low.
7.16.2.Testing SoftReference