Jump to content

Soft reference

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Stumps (talk | contribs) at 23:57, 6 February 2007 (link for cache). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

A soft reference is one of the strengths or levels of 'non strong' reference defined in the Java programming language; the others being weak and phantom.

The garbage collector will always collect weakly referenced objects, but will only collect softly referenced objects when its algorithms decide that memory is low enough to warrant it. Soft and weak references provide two quasi-priorities for non-strongly referenced objects.

Soft references may be used, for example, when writing a cache: weakly referenced objects may disappear too quickly to make the cache useful.