Class Overview
Implements a phantom reference, which is the weakest of the three types of
references. Once the garbage collector decides that an object 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 finalize()
method.
Summary
Public Constructors |
|
PhantomReference(T r, ReferenceQueue<? super T> q)
Constructs a new phantom reference and registers it with the given
reference queue.
|
Public Methods |
T
|
get()
Returns null .
|
[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()
Called before the object's memory is reclaimed by the VM.
|
final
Class<?>
|
getClass()
Returns the unique instance of Class that 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()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method 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.
|
|
Public Constructors
public
PhantomReference
(T r, ReferenceQueue<? super T> q)
Constructs a new phantom reference and registers it with the given
reference queue. The reference queue may be null
, but this case
does not make any sense, since the reference will never be enqueued, and
the get()
method always returns null
.
Parameters
r
| the referent to track |
q
| the queue to register the phantom reference object with
|
Public Methods
public
T
get
()
Returns null
. The referent of a phantom reference is not
accessible.