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
Strong may refer to:
Education
* The Strong, an educational institution in Rochester, New York, United States
* Strong Hall (Lawrence, Kansas), an administrative hall of the University of Kansas
* Strong School, New Haven, Connecticut, United ...
' reference defined in the
Java programming language
Java is a high-level, general-purpose, memory-safe, object-oriented programming language. It is intended to let programmers ''write once, run anywhere'' ( WORA), meaning that compiled Java code can run on all platforms that support Jav ...
, the others being
weak
Weak may refer to:
Songs
* Weak (AJR song), "Weak" (AJR song), 2016
* Weak (Melanie C song), "Weak" (Melanie C song), 2011
* Weak (SWV song), "Weak" (SWV song), 1993
* Weak (Skunk Anansie song), "Weak" (Skunk Anansie song), 1995
* "Weak", a son ...
and
phantom
Phantom, phantoms, or the phantom may refer to:
* Spirit (metaphysics), 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 Phanto ...
. 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 garbage man, garbage collector, trashman (in the U.S), binman or dustman (in the UK), is a person employed by a public or private enterprise to collect and dispose of municipal solid waste (refuse) and recycla ...
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:
Science and technology
* Cache (computing), a technique used in computer storage for easier data access
* Cache (biology) or hoarding, a food storing behavior of animals
* Cache (archaeology), artifacts p ...
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 (or reference cycle) is a series of references where the last object references the first, resulting in a closed loop.
Simple example
A newcomer asks a local where the town library is. "Just in front of the post office," s ...
*
Phantom reference
A phantom reference is a kind of reference in Java (programming language), Java, where the memory can be reclaimed. The phantom reference is one of the strengths or levels of 'non strong reference, strong' reference defined in the Java programming ...
*
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 re ...
External links
Java developer article: 'Reference Objects and Garbage Collection'*
Data types
Memory management
{{compu-lang-stub