NOTE
Netty ByteBuf
Reader/writer indexes, heap/direct buffers, slicing, reference counting, and ownership rules.
This is a historical learning note and may contain outdated or incomplete understanding.
ByteBuf is Netty’s byte-storage abstraction. It maintains separate reader/writer indexes, supports relative/absolute operations, slicing/duplication, composite buffers, and heap/direct implementations.
Many Netty buffers are reference-counted. Derived views may share underlying storage, so ownership is not equivalent to Java object reachability. Code that takes ownership must eventually release according to the API contract; use retained variants when extending a shared buffer’s lifetime.
Leaks are native/process-memory problems as well as correctness problems. Enable leak detection appropriately during development/testing.