title: Understanding how Netty memory-leak would happen if release is not called
body: <p>I have read various StackOverFlow QAs and external links and blogs about memory leak in Netty, starting from <a href="http://netty.io/wiki/reference-counted-objects.html" rel="noreferrer">ReferenceCountedObjects</a> and <a href="https://stackoverflow.com/questions/28647048/why-do-we-need-to-manually-handle-reference-counting-for-netty-bytebuf-if-jvm-gc">ManuallyHandlingReferenceCounting</a>, <a href="https://stackoverflow.com/questions/15781276/buffer-ownership-in-netty-4-how-is-buffer-life-cycle-managed">BufferOwnership</a>, <a href="https://blog.twitter.com/engineering/en_us/a/2013/netty-4-at-twitter-reduced-gc-overhead.html" rel="noreferrer">TwitterBlog</a>, <a href="https://groups.google.com/forum/#!topic/netty/Ve4lnRvFXjM" rel="noreferrer">ChannelOutboundHandlerFlushedBufferLeak</a>, and other links that stem from these pages.</p>
  
  <p>I understand that if the application doesn't release the resource once it is done with it, the actual memory itself will be GCed, but still Netty's pool size will increase and cause memory leak.</p>
  
  <p>Couple of quotes from the links above explaining this are "even if the buffers themselves are garbage collected, the internal data structures used to store the pool will not.", "PooledByteBufAllocator uses the Recycler as well for “pooling” the ByteBuf container (not the memory it refer to itself tho)."</p>
  
  <p>Can someone please explain a bit more about how this could happen? If <code>ByteBuf</code> is a container which is referring to a memory, how can the memory be collected while the <code>ByteBuf</code> is still in Netty memory pool? I visualize that Netty maintains a pool of <code>ByteBuf</code>(s) and reuse the memory it refers to when its reference count becomes 0. With this assumption, I can't understand how the memory itself can be GCed if the <code>ByteBuf</code> is still present in Netty's pool?</p>
  
  <p>Can someone please clarify it in simple terms?</p>