1 *java.lang.ref.SoftReference* *SoftReference* Soft reference objects, which are
3 public class SoftReference<T>
4 extends |java.lang.ref.Reference|
6 |java.lang.ref.SoftReference_Description|
7 |java.lang.ref.SoftReference_Fields|
8 |java.lang.ref.SoftReference_Constructors|
9 |java.lang.ref.SoftReference_Methods|
11 ================================================================================
13 *java.lang.ref.SoftReference_Constructors*
14 |java.lang.ref.SoftReference(T)|Creates a new soft reference that refers to the
15 |java.lang.ref.SoftReference(T,ReferenceQueue<?superT>)|Creates a new soft refe
17 *java.lang.ref.SoftReference_Methods*
18 |java.lang.ref.SoftReference.get()|Returns this reference object's referent.
20 *java.lang.ref.SoftReference_Description*
22 Soft reference objects, which are cleared at the discretion of the garbage
23 collector in response to memory demand. Soft references are most often used to
24 implement memory-sensitive caches.
26 Suppose that the garbage collector determines at a certain point in time that
27 an object is softly reachable. At that time it may choose to clear atomically
28 all soft references to that object and all soft references to any other
29 softly-reachable objects from which that object is reachable through a chain of
30 strong references. At the same time or at some later time it will enqueue those
31 newly-cleared soft references that are registered with reference queues.
33 All soft references to softly-reachable objects are guaranteed to have been
34 cleared before the virtual machine throws an OutOfMemoryError. Otherwise no
35 constraints are placed upon the time at which a soft reference will be cleared
36 or the order in which a set of such references to different objects will be
37 cleared. Virtual machine implementations are, however, encouraged to bias
38 against clearing recently-created or recently-used soft references.
40 Direct instances of this class may be used to implement simple caches; this
41 class or derived subclasses may also be used in larger data structures to
42 implement more sophisticated caches. As long as the referent of a soft
43 reference is strongly reachable, that is, is actually in use, the soft
44 reference will not be cleared. Thus a sophisticated cache can, for example,
45 prevent its most recently used entries from being discarded by keeping strong
46 referents to those entries, leaving the remaining entries to be discarded at
47 the discretion of the garbage collector.
51 *java.lang.ref.SoftReference(T)*
53 public SoftReference(T referent)
55 Creates a new soft reference that refers to the given object. The new reference
56 is not registered with any queue.
58 referent - object the new soft reference will refer to
60 *java.lang.ref.SoftReference(T,ReferenceQueue<?superT>)*
64 java.lang.ref.ReferenceQueue<? super T> q)
66 Creates a new soft reference that refers to the given object and is registered
69 referent - object the new soft reference will refer to
70 q - the queue with which the reference is to be registered, or null if registration
73 *java.lang.ref.SoftReference.get()*
77 Returns this reference object's referent. If this reference object has been
78 cleared, either by the program or by the garbage collector, then this method
83 Returns: The object to which this reference refers, or null if this reference object has