Class LeakDetect


  • public final class LeakDetect
    extends java.lang.Object
    General purpose object reference leak detector with recovery.

    A reference to the phantom must still be maintained somewhere... For example: private final AtomicReference<PhantomReference<AsyncFutureListener<?>>> _phantom = new AtomicReference<>();

    Then using the LeakDetect tool is as simple as: PhantomReference<AsyncFutureListener<?>> phantom = LeakDetect .newReference(responseListener, () -> ctx.executor().execute(() -> promise.setSuccess(internalBuildErrorResponse(request, new IllegalStateException("Reference lost"))))); promise.addListener(future -> { phantom.clear(); _phantom.compareAndSet(phantom, null); }); _phantom.lazySet(phantom);

    Note that the recovery should not reference any object which may hold a reference to the object which is being monitored for leaks.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> java.lang.ref.PhantomReference<T> newReference​(T object, java.lang.Runnable recover)
      Make a phantom reference for leak detection.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • newReference

        public static <T> java.lang.ref.PhantomReference<T> newReference​(T object,
                                                                         java.lang.Runnable recover)
        Make a phantom reference for leak detection. Be sure to call Reference.clear() when the object is no longer considered leaked.
        Parameters:
        object - Object to monitor.
        recover - Task to invoke when a leak occurs.
        Returns:
        Phantom reference.