在使用netty实现服务端或者客户端读取数据时,我们一般会继承SimpleChannelInboundHandler重写channelRead0方法,这个netty会自动帮我们释放堆外内存。
但是我们在业务逻辑中使用类似readBytes方法读取到ByteBuf则需要我们手动调用release()方法去释放,不然就会挤压,jvm的GC也不会对其进行回收,直到netty抛出堆外内存溢出异常。
io.netty.handler.codec.DecoderException: io.netty.util.internal.OutOfDirectMemoryError: failed to allocate 16777216 byte(s) of direct memory (used: 1879048192, max: 1884815360)