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 295c24e246
commit 27cc69b5cb

View File

@ -131,6 +131,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.
*/