NOTE

Using Netty ByteBuf Allocation Safely

Allocator usage, capacity, slicing, copying, reference-count handling, and leak-safe buffer ownership.

JavaCreated Updated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

Allocate buffers through the channel/context allocator when possible so application code follows the configured allocator strategy.

Choose between slice/duplicate and copy deliberately: views can share storage and reference-count lifetime; copies own separate bytes at additional CPU/memory cost.

When a handler consumes a reference-counted message without forwarding it, release it exactly once. When retaining it beyond the current callback/forwarding contract, use the appropriate retain/retained API. Reference-count bugs can become leaks or use-after-release failures.

Loading helpful count