严重:泄漏:在垃圾回收之前未调用ByteBuf.release().净额 [英] SEVERE: LEAK: ByteBuf.release() was not called before it's garbage-collected. Netty

查看:2838
本文介绍了严重:泄漏:在垃圾回收之前未调用ByteBuf.release().净额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一些游戏服务器,并且我刚刚与大约10位伙伴进行了测试.一切都进行得很顺利,我们玩了大约10分钟,在游戏的某个时刻,游戏服务器停止了服务客户端,断开了所有人的连接,而且我连接到运行游戏的VPS的SSH也断开了(我不确定为什么),但在断开连接之前,我总是收到此消息:

I have created some game server, and I just tested it with around 10 mates. Everything went smooth, we played around 10 minutes, and at some point of the game, the game server stopped serving clients, disconnected everyone, and also my SSH that was connected to the VPS that runs the game disconnected aswell (I am not sure why) but before the disconnection I always get this message:

Sep 20, 2017 5:14:11 PM io.netty.util.ResourceLeakDetector reportUntracedLeak
SEVERE: LEAK: ByteBuf.release() was not called before it's garbage-collected. Enable advanced leak reporting to find out where the leak occurred. To enable advanced leak reporting, specify the JVM option '-Dio.netty.leakDetection.level=advanced' or call ResourceLeakDetector.setLevel() See http://netty.io/wiki/reference-counted-objects.html for more information.

我需要调试并知道此消息的真正含义,该错误的方向是什么.

I need to debug and know what does this message really mean, what is the direction of this bug.

我真的不知道我的代码的哪一部分需要弄清楚.

I don't really know what part of my code needed to figure it out.

private void decodeData(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) {
    if (buffer.readableBytes() >= length) {
        ByteBuf data = buffer.readBytes(length);
        out.add(new Packet(opcode, data));
        setState(PacketDecodeState.OPCODE);
    }
}

读取完数据后,我不会再调用buffer.release(),因为那样一来它就不会真正处理任何数据包,只是一种错误的行为,而且我肯定将其放在那里是错误的.

After I finish reading the data, I do not call buffer.release() because then it won't really process any packets, just a wrong behavior and Im sure it is wrong to put it there.

推荐答案

由于您的Packet拥有对新创建的ByteBuf的引用,因此您需要确保调用此ByteBufByteBuf.release(),否则创建一个内存泄漏.

As your Packet holds a reference to a new created ByteBuf you need to ensure you call ByteBuf.release() of this ByteBuf otherwise you create a memory leak.

这篇关于严重:泄漏:在垃圾回收之前未调用ByteBuf.release().净额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆