Soft reference

A soft reference is a reference that is garbage-collected less aggressively. The 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. Soft and weak references provide two quasi-priorities for non-strongly referenced objects: 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 references may be used, for example, to write a free memory sensitive cache such that cached objects are kept until there is enough heap space. In some cases weakly referenced objects may be reclaimed too quickly to make such a cache useful.

See also

External links

This article is issued from Wikipedia - version of the 11/11/2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.