Soft references

Soft references are Java object classes that are to be treated specially by the garbage collector. Besides from standard "strong" references, there are soft references, weak references, and phantom references, all of which provide different levels of reachability than a standard reference. Soft and weak references are allowed to be garbage collected if memory is scarce, and are typically referenced by a wrapper object. A wrapper object is normally a Reference instance. Thus, soft and weak references may automatically be removed from a wrapper object by the GC if no other references exist. Phantom references, never reachable from their wrapper objects, can be used to implement finalization with safer semantics.

Get Oracle JRockit now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.