java.lang.ref

Class PhantomReference<T>


  • public class PhantomReference<T>
    extends Reference<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, 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.

    Since:
    1.2
    • Constructor Detail

      • PhantomReference

        public PhantomReference(T referent,
                        ReferenceQueue<? 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
    • Method Detail

      • get

        public T get()
        Returns this reference object's referent. Because the referent of a phantom reference is always inaccessible, this method always returns null.
        Overrides:
        get in class Reference<T>
        Returns:
        null

Document created the 11/06/2005, last modified the 04/03/2020
Source of the printed document:https://www.gaudry.be/en/java-api-rf-java/lang/ref/PhantomReference.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : https://docs.oracle.com

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut