search

Home  >  Q&A  >  body text

java - netty中的ReferenceCountUtil.release()方法具体作用是什么?

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

迷茫迷茫2771 days ago1110

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 17:49:56

    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.

    reply
    0
  • PHPz

    PHPz2017-04-17 17:49:56

    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

    reply
    0
  • Cancelreply