This class works the same way as WeakReference, but when constructed, it also holds the referent by a strong reference. This prevents it from being garbage collected until makeWeak() is called.
This class is useful when dynamic caching is implemented. Making a reference weak 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 | StrongWeakReference( Creates a new weak reference that refers to the given object. |
public | StrongWeakReference( Creates a new weak reference that refers to the given object and is
registered with the given queue. |
This method is invoked only by Java code; when the garbage collector clears references it does so directly, without invoking this method.
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.
Reference.get() returns null
.)
If this method succeeds, then the following calls to Reference.get() will return non-null
.
true
if the reference was successfully made strong.this
reference weak by clearing its strong reference.