public class PhantomReference<T> extends Reference<T>
obj is
phantom-reachable, it is being enqueued
on the corresponding queue, but its referent is not cleared. That is, the
reference queue of the phantom reference must explicitly be processed by some
application code. As a consequence, a phantom reference that is not
registered with any reference queue does not make any sense.
Phantom references are useful for implementing cleanup operations that are
necessary before an object gets garbage-collected. They are sometimes more
flexible than the Object.finalize() method.
pendingNext| Constructor and Description |
|---|
PhantomReference(T r,
ReferenceQueue<? super T> q)
Constructs a new phantom reference and registers it with the given
reference queue.
|
| Modifier and Type | Method and Description |
|---|---|
T |
get()
Returns
null. |
clear, enqueue, enqueueInternal, isEnqueuedpublic PhantomReference(T r, ReferenceQueue<? super T> q)
null, but this case
does not make any sense, since the reference will never be enqueued, and
the get() method always returns null.r - the referent to trackq - the queue to register the phantom reference object with