Soft reference

From Wikipedia, the free encyclopedia
Jump to: navigation, search

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. In order from strongest to weakest, they are: strong, soft, weak, phantom.

Soft references behave almost identically to weak references, but they are garbage-collected less aggressively: 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.

See also[edit]

External links[edit]