netty内存泄露检测

  1. jvm增加参数
1
-Dio.netty.leakDetectionLevel=PARANOID -XX:MaxDirectMemorySize=5M -XX:NativeMemoryTracking=detail -Xms5m -Xmx10m

配置如图

或者在代码中配置

1
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.ADVANCED);
  1. 手动在解码器中增加泄露点

  1. 启动客户端连接后在定时任务中发送消息, 由于解码器内存泄露, 会出现类似如下异常
1
2
3
4
5
6
7
8
[worker-3-1] ERROR io.netty.util.ResourceLeakDetector - LEAK: ByteBuf.release() was not called before it's garbage-collected. See https://netty.io/wiki/reference-counted-objects.html for more information.
Recent access records:
#1:
io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:285)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93)
  1. 感谢阅读。如果您觉得不错,请关注公众号【当我遇上你】,您的支持是我写作的最大动力。