The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.lang.ref  [3 examples]

e106. 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.
    }

 Related Examples
e107. Determining When an Object Is No Longer Used
e108. Determining When an Object Will Be Reclaimed


© 2002 Addison-Wesley.