av.ref
Class StrongSoftReference<T>
java.lang.Object
java.lang.ref.Reference<T>
java.lang.ref.SoftReference<T>
av.ref.StrongSoftReference<T>
- Type Parameters:
T -
- All Implemented Interfaces:
- Reference<T>
public class StrongSoftReference<T>
- extends SoftReference<T>
- implements Reference<T>
This class inherits behaviors from SoftReference,
whereas an instance will keep a strong reference to the referent at
construction, thus prevent it from being automatically cleared by gc until
the strong reference is explicitly cleared later.
When later the strong protection is not required any more, invocation to
clearStrong() will clear the strong reference and make the referent
possiblily reach softly reachable state then subsequently the soft reference
also cleared by gc and finally the referent get garbage collected.
But the gc is not immediately clearing the soft reference right after the
strong reference has been cleared. Meanwhile, there are still chances to
restore the strong reference by invoking ensureStrong(). If it
returns true, the strong reference has been successfully restored, and the
referent is again under protection from being discarded by gc. The other case
is the soft reference has already been cleared , it will cause subsquent
invocations to SoftReference.get() keep returning null, and there's no way to get
the referent back any more.
- Author:
- Compl
|
Method Summary |
void |
clearStrong()
Clear the strong reference to the referent to allow it to get softly
reachable state thus further eligible for garbage collection. |
boolean |
ensureStrong()
Try to restore the strong reference if it has ever been cleared by prior
invocation to clearStrong(). |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
StrongSoftReference
public StrongSoftReference(T referent)
StrongSoftReference
public StrongSoftReference(T referent,
ReferenceQueue<T> q)
clearStrong
public void clearStrong()
- Clear the strong reference to the referent to allow it to get softly
reachable state thus further eligible for garbage collection.
ensureStrong
public boolean ensureStrong()
- Try to restore the strong reference if it has ever been cleared by prior
invocation to
clearStrong(). If it has never been cleared,
return true directly.
- Returns:
- whether the referent is strong referenced after this invocation.
Copyright© 2006 Ableverse Platform. All rights reserved.