Soft reference
Appearance
![]() | This article is actively undergoing a major edit for a little while. To help avoid edit conflicts, please do not edit this page while this message is displayed. This page was last edited at 04:47, 6 February 2007 (UTC) (18 years ago) – this estimate is cached, . Please remove this template if this page hasn't been edited for a significant time. If you are the editor who added this template, please be sure to remove it or replace it with {{Under construction}} between editing sessions. |
A soft reference is one of the strengths 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-strong;y referenced objects.
Soft references are useful when making a cache: weakly referenced objects may disappear too quickly to make the cache useful.