Soft reference
Encyclopedia
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.
Strong reference
In computer programming, a strong reference is a normal reference that protects the referred object from collection by a garbage collector. The term is used to distinguish the reference from weak references.a Category:Programming constructs...
' reference defined in the Java programming language
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
, the others being weak
Weak reference
In computer programming, a weak reference is a reference that does not protect the referenced object from collection by a garbage collector . An object referenced only by weak references is considered unreachable and so may be collected at any time...
and phantom
Phantom reference
A 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....
.
The garbage collector
Garbage collection (computer science)
In computer science, garbage collection is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program...
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
Cache
In computer engineering, a cache is a component that transparently stores data so that future requests for that data can be served faster. The data that is stored within a cache might be values that have been computed earlier or duplicates of original values that are stored elsewhere...
: weakly referenced objects may disappear too quickly to make the cache useful.