# PhantomReference

public class **PhantomReference** extends [Reference](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ref/Reference.html)\<T\>  
Phantom reference objects, which are enqueued after the collector
determines that their referents may otherwise be reclaimed. Phantom
references are most often used for scheduling pre-mortem cleanup actions in
a more flexible way than is possible with the Java finalization mechanism.

If the garbage collector determines at a certain point in time that the
referent of a phantom reference is [phantom reachable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ref/package-summary#reachability), then at that
time or at some later time it will enqueue the reference.

In order to ensure that a reclaimable object remains so, the referent of
a phantom reference may not be retrieved: The `get` method of a
phantom reference always returns `null`.

Unlike soft and weak references, phantom references are not
automatically cleared by the garbage collector as they are enqueued. An
object that is reachable via phantom references will remain so until all
such references are cleared or themselves become unreachable.

### Public Constructor Summary

|---|---|
|   | [PhantomReference](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ref/PhantomReference.html#PhantomReference(T,%20java.lang.ref.ReferenceQueue<?%20super%20T>))(T referent, [ReferenceQueue](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ref/ReferenceQueue.html)\<? super T\> q) Creates a new phantom reference that refers to the given object and is registered with the given queue. |

### Public Method Summary

|---|---|
| T | [get](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ref/PhantomReference.html#get())() Returns this reference object's referent. |

### Inherited Method Summary

From class [java.lang.ref.Reference](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ref/Reference.html)

|---|---|
| void | [clear](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ref/Reference.html#clear())() Clears this reference object. |
| boolean | [enqueue](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ref/Reference.html#enqueue())() Adds this reference object to the queue with which it is registered, if any. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ref/Reference.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| T | [get](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ref/Reference.html#get())() Returns this reference object's referent. |
| boolean | [isEnqueued](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ref/Reference.html#isEnqueued())() Tells whether or not this reference object has been enqueued, either by the program or by the garbage collector. |

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#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](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#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](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, 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](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) 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](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

## Public Constructors

#### public
**PhantomReference**
(T referent, [ReferenceQueue](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ref/ReferenceQueue.html)\<? super T\> q)

Creates a new phantom reference that refers to the given object and
is registered with the given queue.

It is possible to create a phantom reference with a null
queue, but such a reference is completely useless: Its get
method will always return null and, since it does not have a queue, it
will never be enqueued.

##### Parameters

| referent | the object the new phantom reference will refer to |
| q | the queue with which the reference is to be registered, or null if registration is not required |
|---|---|

## Public Methods

#### public T
**get**
()

Returns this reference object's referent. Because the referent of a
phantom reference is always inaccessible, this method always returns
`null`.

##### Returns

- `null`