java.lang.ref
Class WeakReference
java.lang.Object
|
+--java.lang.ref.Reference
|
+--java.lang.ref.WeakReference
A weak reference will be cleared, if the object is only weakly
reachable. It is useful for lookup tables, where you aren't
interested in an entry, if the key isn't reachable anymore.
WeakHashtable
is a complete implementation of such a
table.
It is also useful to make objects unique: You create a set of weak
references to those objects, and when you create a new object you
look in this set, if the object already exists and return it. If
an object is not referenced anymore, the reference will
automatically cleared, and you may remove it from the set.
Author:See Also:
WeakReference
public WeakReference(java.lang.Object referent)
Create a new weak reference, that is not registered to any queue.
Parameters:
WeakReference
public WeakReference(java.lang.Object referent, java.lang.ref.ReferenceQueue q)
Create a new weak reference.
Parameters:
Throws:
WeakHashtable
is a complete implementation of such a table.It is also useful to make objects unique: You create a set of weak references to those objects, and when you create a new object you look in this set, if the object already exists and return it. If an object is not referenced anymore, the reference will automatically cleared, and you may remove it from the set.