java - netty中的ReferenceCountUtil.release()方法具体作用是什么?
迷茫
迷茫 2017-04-17 17:47:56
0
2
1114

在什么情况下使用这个函数?

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
Peter_Zhu

ReferenceCountUtil.release() is actually a wrapper of the ByteBuf.release() method (inherited from the ReferenceCounted interface). ByteBuf in netty4 uses reference counting (netty4 implements an optional ByteBuf pool). The reference count value of each newly allocated ByteBuf is 1. Each time a reference is added to this ByteBuf object, the ByteBuf.retain() method needs to be called. , and every time a reference is reduced, the ByteBuf.release() method needs to be called. When the reference count value of this ByteBuf object is 0, it means that this object can be recycled. I just use ByteBuf to illustrate this. There are other objects that implement the ReferenceCounted interface. The same applies at this time.

PHPzhong

ByteBufs read from InBound must be released manually, and ByteBufs created by oneself must be released by oneself. This release method needs to be called in these two places.
When writing Bytebuf to OutBound, netty is responsible for releasing it, and there is no need to manually call release

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template