Skip to content

Most visited

Recently visited

navigation
Added in API level 1

PhantomReference

public class PhantomReference
extends Reference<T>

java.lang.Object
   ↳ java.lang.ref.Reference<T>
     ↳ java.lang.ref.PhantomReference<T>


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.

Inherited methods

From class java.lang.ref.Reference
From class java.lang.Object

Public constructors

PhantomReference

Added in API level 1
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 T: the referent to track
q ReferenceQueue: the queue to register the phantom reference object with

Public methods

get

Added in API level 1
T get ()

Returns null. The referent of a phantom reference is not accessible.

Returns
T null (always)
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.