最近在研究netty,看书(Netty in Action)资源管理,动手写了一个ChannelHandler的实现,如下
public class EchoServerHandler extends ChannelInboundHandlerAdapter{
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg)
throws Exception {
System.out.println("channel read handler 1......");
ByteBuf buf = ctx.alloc().buffer();
buf.writeBytes("hehehehehehe".getBytes());
ctx.fireChannelRead(buf);
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
System.out.println("channelReadComplete1......"+ctx.channel().hashCode());
super.channelReadComplete(ctx);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
throws Exception {
cause.printStackTrace();
ctx.close();
}
}
已经在程序中设置了
-Dio.netty.leakDetection.level=PARANOID
最高检测级别
在channelRead()方法中对msg对象并没有做显示释放操作,也没有往下传递给其他的ChannelHandler(后边还有一个处理输入的ChannelHandler),为什么没有打印出警告内存没有释放的日志呢?
本人netty菜鸟,还望各位大神能够不吝赐教 ,感激不禁 !