Known Direct Subclasses
|
Class Overview
Implements a weak reference, which is the middle of the three types of
references. Once the garbage collector decides that an object obj
is
is weakly-reachable, the following
happens:
-
A set
ref
of references is determined. ref
contains the
following elements:
-
All weak references pointing to
obj
.
-
All weak references pointing to objects from which
obj
is
either strongly or softly reachable.
-
All references in
ref
are atomically cleared.
-
All objects formerly being referenced by
ref
become eligible for
finalization.
-
At some future point, all references in
ref
will be enqueued
with their corresponding reference queues, if any.
Weak references are useful for mappings that should have their entries
removed automatically once they are not referenced any more (from outside).
The difference between a
SoftReference
and a
WeakReference
is
the point of time at which the decision is made to clear and enqueue the
reference:
-
A
SoftReference
should be cleared and enqueued as late as
possible, that is, in case the VM is in danger of running out of
memory.
-
A
WeakReference
may be cleared and enqueued as soon as is
known to be weakly-referenced.
Summary
[Expand]
Inherited Methods |
From class java.lang.ref.Reference
void
|
clear()
Makes the referent null .
|
boolean
|
enqueue()
Forces the reference object to be enqueued if it has been associated with
a queue.
|
T
|
get()
Returns the referent of the reference object.
|
boolean
|
isEnqueued()
Checks whether the reference object has been enqueued.
|
|
From class java.lang.Object
Object
|
clone()
Creates and returns a copy of this Object .
|
boolean
|
equals(Object o)
Compares this instance with the specified object and indicates if they
are equal.
|
void
|
finalize()
Is called before the object's memory is being reclaimed by the VM.
|
final
Class<? extends Object>
|
getClass()
Returns the unique instance of Class which represents this
object's class.
|
int
|
hashCode()
Returns an integer hash code for this object.
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
final
void
|
wait(long millis, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait(long millis)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
|
Public Constructors
public
WeakReference
(T r)
Constructs a new weak reference to the given referent. The newly created
reference is not registered with any reference queue.
public
WeakReference
(T r, ReferenceQueue<? super T> q)
Constructs a new weak reference to the given referent. The newly created
reference is registered with the given reference queue.
Parameters
r
| the referent to track |
q
| the queue to register to the reference object with. A null value
results in a weak reference that is not associated with any
queue. |