Introduce ReferenceCounted.refCnt()

Motivation:

When debugging netty memory leaks, it's sometimes helpful to
print the object's reference count.

Modifications:

Add `refCnt` methods to set of already exitsting helpers for ref coutned
objects.

Result:

Users will have utility to print object's ref count without much of a
boilerplate.
This commit is contained in:
Lukasz Strzalkowski 2017-04-08 17:54:55 -07:00 committed by Norman Maurer
parent 7b6119a0a4
commit 7bd0905969

View File

@ -156,6 +156,14 @@ public final class ReferenceCountUtil {
return msg;
}
/**
* Returns reference count of a {@link ReferenceCounted} object. If object is not type of
* {@link ReferenceCounted}, {@code -1} is returned.
*/
public static int refCnt(Object msg) {
return msg instanceof ReferenceCounted ? ((ReferenceCounted) msg).refCnt() : -1;
}
/**
* Releases the objects when the thread that called {@link #releaseLater(Object)} has been terminated.
*/