1

I am using Netty 4.1.17-Final with Direct Buffer.

We send and receive 100 MB of byte[] in the test program, and when decoder reaches 100 MB, we discard it without doing anything.

@Override
public void decode(ByteBuffer _in, List<Object> _out) {
    if (_in.remaining() == size) {   // size = 100 * 1024 * 1024
        _in.get(new byte[size]);
    }
}

I explicitly executed GC at the end of the test and tried sleeping for about 10 seconds in anticipation of Cleaner releasing. However, Direct Buffer was not partially released, but Netty did not report a leak in ByteBuf.

Direct Buffer graph link

I have given the following options to the test program.
-Dio.netty.maxDirectMemory=0 -Dio.netty.leakDetection.level=PARANOID

I asked related questions below.
PooledUnsafeDirectByteBuf not found in DirectMemory

nikai
  • 27
  • 1
  • 6

1 Answers1

0

By default netty pools buffers so if you use the default allocator this is the case here.

If you don't want to pool you should use UnpooledByteBufAllocator. This can be configured during bootstrapping with ChannelOption.ALLOCATOR.

Norman Maurer
  • 23,104
  • 2
  • 33
  • 31
  • thank you for your answer. As you said, pooled Buffer was used. When I changed it to allocate with UnpooledByteBufAllocator, Direct Buffer was released cleanly. Transition of Direct Buffer Usage > https://i.stack.imgur.com/8GSa7.jpg – nikai Jun 25 '18 at 01:29
  • Which system property can I set initial size and maximum size of pool size? Also, I predicted that pool is the sum of chank x arena, but the calculations did not match. In my environment chank is 16 MB, Area is 4 core x 2 = 8, the lowest limit of Direct Buffer after GC was about 25 MB. – nikai Jun 25 '18 at 02:41