Package ej.bon

Class EnqueuedWeakReference<T>

  • Type Parameters:
    T - the type of enqueued objects

    public class EnqueuedWeakReference<T>
    extends WeakReference<T>
    EnqueuedWeakReference are objects that are queued in an ReferenceQueue by the system when the object they point at (see Reference.get()) is set to null by the system. A typical use is to subclass EnqueuedWeakReference with classes that hold native handles that need to be freed at the native level.
    • Constructor Detail

      • EnqueuedWeakReference

        public EnqueuedWeakReference​(T ref,
                                     @Nullable
                                     ReferenceQueue<? super T> queue)
        Creates a new EnqueuedWeakReference.

        The given reference can be retrieved using Reference.get() until the object is garbage collected. Then the method will return null.

        Parameters:
        ref - object the new weak reference will refer to
        queue - the queue with which the reference is to be registered