This class works the same way as SoftReference, but when constructed, it also holds the referent by a strong reference. This prevents it from being garbage collected until makeSoft() is called.
This class is useful when dynamic caching is implemented. Making a reference soft can allow the referenced object to be garbage collected, but calling makeStrong() again, can allow the client to reuse a not yet garbage collected object instead of creating a new one.
public | StrongSoftReference( |
public | StrongSoftReference( |
This method is invoked only by Java code; when the garbage collector clears references it does so directly, without invoking this method.
this
reference soft by clearing its strong reference.this
reference strong again, by assigning the strong reference to the referent.
This method can fail and return false
, if the referenced object was already garbage collected. (I.e.
SoftReference.get() returns null
.)
If this method succeeds, then the following calls to SoftReference.get() will return non-null
.
true
if the reference was successfully made strong.