# WeakReference

public class **WeakReference** extends [Reference](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ref/Reference.html)\<T\>  
Weak reference objects, which do not prevent their referents from being
made finalizable, finalized, and then reclaimed. Weak references are most
often used to implement canonicalizing mappings.

Suppose that the garbage collector determines at a certain point in time
that an object is [weakly
reachable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ref/package-summary#reachability). At that time it will atomically clear all weak references to
that object and all weak references to any other weakly-reachable objects
from which that object is reachable through a chain of strong and soft
references. At the same time it will declare all of the formerly
weakly-reachable objects to be finalizable. At the same time or at some
later time it will enqueue those newly-cleared weak references that are
registered with reference queues.

### Public Constructor Summary

|---|---|
|   | [WeakReference](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ref/WeakReference.html#WeakReference(T))(T referent) Creates a new weak reference that refers to the given object. |
|   | [WeakReference](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/ref/WeakReference.html#WeakReference(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 weak reference that refers to the given object and is registered with the given queue. |

### 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
**WeakReference**
(T referent)

Creates a new weak reference that refers to the given object. The new
reference is not registered with any queue.

##### Parameters

| referent | object the new weak reference will refer to |
|---|---|

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

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

##### Parameters

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