Soft Reference
   HOME

TheInfoList



OR:

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 Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let programmers ''write once, run anywh ...
, the others being weak and
phantom Phantom may refer to: * Spirit (animating force), the vital principle or animating force within all living things ** Ghost, the soul or spirit of a dead person or animal that can appear to the living Aircraft * Boeing Phantom Ray, a stealthy un ...
. 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 A waste collector, also known as a garbageman, garbage collector, trashman (in the US), binman or (rarely) dustman (in the UK), is a person employed by a public or private enterprise to collect and dispose of municipal solid waste (refuse) and r ...
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 Cache, caching, or caché may refer to: Places United States * Cache, Idaho, an unincorporated community * Cache, Illinois, an unincorporated community * Cache, Oklahoma, a city in Comanche County * Cache, Utah, Cache County, Utah * Cache County ...
such that cached objects are kept until there is not enough heap space. In some cases weakly referenced objects may be reclaimed too quickly to make such a cache useful.


See also

*
Circular reference A circular reference is a series of references where the last object references the first, resulting in a closed loop. In language A circular reference is not to be confused with the logical fallacy of a circular argument. Although a circular ...
*
Phantom reference A phantom reference is a kind of reference in Java, where the memory can be reclaimed. The phantom reference is one of the strengths or levels of 'non strong' reference defined in the Java programming language; the others being weak and soft. Pha ...
*
Weak reference In computer programming, a weak reference is a reference that does not protect the referenced object from collection by a garbage collector, unlike a strong reference. An object referenced ''only'' by weak references – meaning "every chain of ref ...


External links


Java developer article: 'Reference Objects and Garbage Collection'
* Data types Memory management {{compu-lang-stub