Holding onto an Object Until Memory Becomes Low
A soft reference holds onto its referent until memory becomes low.
// Create up the soft reference.
SoftReference sr = new SoftReference(object);
// Use the soft reference.
Object o = sr.get();
if (o != null) {
process(o);
} else {
// The object is being collected or has been reclaimed.
}
Post a comment