Java examples for Java Virtual Machine:Utility
Holding onto an Object Until Memory Becomes Low
import java.awt.Graphics; import java.lang.ref.SoftReference; public class Main { public void m() { // Create up the soft reference. Object object = ""; SoftReference sr = new SoftReference(object); // Use the soft reference. Object o = sr.get();/* ww w. j av a 2 s .c o m*/ if (o != null) { // process(o); } else { // The object is being collected or has been reclaimed. } } }