Class LeakDetect
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
Modifier and TypeMethodDescriptionstatic <T> PhantomReference<T>
newReference
(T object, Runnable recover) Make a phantom reference for leak detection.
-
Method Details
-
newReference
Make a phantom reference for leak detection. Be sure to callReference.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.
-