Рейтинг темы:
  • 0 Голос(ов) - 0 в среднем
  • 1
  • 2
  • 3
  • 4
  • 5
error in java
#1
I am have this error keep show to me in console of Battle ?
what fix for it need some help ?????

Код:
[05:55:10|ERROR|nioEventLoopGroup-2-1    |io.netty.util.ResourceLeakDetector             ] LEAK: ByteBuf.release() was not called before it's garbage-collected.
Recent access records: 1
#1:
    io.netty.buffer.AdvancedLeakAwareByteBuf.writeBytes(AdvancedLeakAwareByteBuf.java:559)
    io.netty.buffer.Unpooled.copiedBuffer(Unpooled.java:421)
    ru.pb.battle.network.client.BattleClientConnection.channelRead0(BattleClientConnection.java:81)
    ru.pb.battle.network.client.BattleClientConnection.channelRead0(BattleClientConnection.java:22)
    io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:103)
    io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:338)
    io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:324)
    io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785)
    io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:93)
    io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:485)
    io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:452)
    io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:346)
    io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
    java.lang.Thread.run(Unknown Source)
Created at:
    io.netty.util.ResourceLeakDetector.open(ResourceLeakDetector.java:190)
    io.netty.buffer.AbstractByteBufAllocator.toLeakAwareBuffer(AbstractByteBufAllocator.java:42)
    io.netty.buffer.UnpooledByteBufAllocator.newDirectBuffer(UnpooledByteBufAllocator.java:55)
    io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:155)
    io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:146)
    io.netty.buffer.Unpooled.directBuffer(Unpooled.java:127)
    io.netty.buffer.Unpooled.copiedBuffer(Unpooled.java:417)
    ru.pb.battle.network.client.BattleClientConnection.channelRead0(BattleClientConnection.java:81)
    ru.pb.battle.network.client.BattleClientConnection.channelRead0(BattleClientConnection.java:22)
    io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:103)
    io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:338)
    io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:324)
    io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785)
    io.netty.channel.nio.AbstractNioMessageChannel$NioMessageUnsafe.read(AbstractNioMessageChannel.java:93)
    io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:485)
    io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:452)
    io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:346)
    io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
    java.lang.Thread.run(Unknown Source)
Ответ
#2
Give me an example of channelRead method.
Ответ
#3
PROGRAMMATOR Написал:Give me an example of channelRead method.

[SRC="java"]import io.netty.channel.socket.DatagramPacket;

import java.net.InetSocketAddress;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ru.pb.battle.controllers.RoomController;
import ru.pb.battle.models.Player;
import ru.pb.battle.models.Room;
import ru.pb.battle.utils.ByteBuffer;

/**
* @author DarkSkeleton
*/
public class BattleClientConnection extends SimpleChannelInboundHandler<DatagramPacket> {

private static final Logger log = LoggerFactory.getLogger(BattleClientConnection.class);

@Override
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
ByteBuf bb = msg.content();
byte opcode = bb.readByte();
switch(opcode)
{
case 65: {
// ByteBuffer _buffer2 = new ByteBuffer();
// _buffer2.writeC((byte)66);
// _buffer2.writeC((byte) 0);
// _buffer2.writeB(new byte[5]);
// _buffer2.writeC((byte) 0x0b);
// _buffer2.writeB(new byte[3]);
// ctx.writeAndFlush(new DatagramPacket(Unpooled.copiedBuffer(_buffer2.getData(), 0, _buffer2.getData().length), msg.sender()));
Room room = RoomController.getInstance().getRoom(msg.sender().getAddress());
if(room != null) {
if(room.inetAddress.equals(msg.sender().getAddress())) {
ByteBuffer _buffer = new ByteBuffer();
_buffer.writeC((byte) 66);
_buffer.writeC((byte) 0);
_buffer.writeB(new byte[5]);
_buffer.writeC((byte) 0x0b);
_buffer.writeB(new byte[3]);
room.isConnected = true;
room.port = msg.sender().getPort();
ctx.writeAndFlush(new DatagramPacket(Unpooled.copiedBuffer(_buffer.getData(), 0, _buffer.getData().length), msg.sender()));
} else {
Player player = RoomController.getInstance().getPlayer(msg.sender().getAddress());
if(player != null) {
ByteBuffer _buffer = new ByteBuffer();
_buffer.writeC((byte) 66);
_buffer.writeC((byte) 0);
_buffer.writeB(new byte[5]);
_buffer.writeC((byte) 0x0b);
_buffer.writeB(new byte[3]);
player.isConnected = true;
player.playerPort = msg.sender().getPort();
ctx.writeAndFlush(new DatagramPacket(Unpooled.copiedBuffer(_buffer.getData(), 0, _buffer.getData().length), msg.sender()));
}
}
}
break;
}
case (byte) 131:
case (byte) 132:
case 84:
case 97:
case 4:
case 3: {
Room room = RoomController.getInstance().getRoom(msg.sender().getAddress());
if(room != null) {
if(room.inetAddress.equals(msg.sender().getAddress())) {
for(Player player : room.getPlayers().values()) {
if(player.isActive) {
if(player.playerPort > 0) {
ctx.writeAndFlush(new PBUDPServerPacket(opcode, Unpooled.copiedBuffer(msg.content()), new InetSocketAddress(player.playerIP, player.playerPort)).getPacket());
}
}
}
} else {
if(room.isActive) {
if(room.port > 0) {
ctx.writeAndFlush(new PBUDPServerPacket(opcode, Unpooled.copiedBuffer(msg.content()), new InetSocketAddress(room.inetAddress, room.port)).getPacket());
}
}
}
}
break;
}
case 67: {
Player player = RoomController.getInstance().getPlayer(msg.sender().getAddress());
if(player != null) {
player.isActive = false;
player.isConnected = false;
}
break;
}

}
bb.release();
}

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
cause.printStackTrace();
// We don't close the channel because we can keep serving requests.
}
}
[/SRC]

so what the fix of this error what called JavaLeak ?
@PROGRAMMATOR
Ответ
#4
Try this code:
Код:
ResourceLeakDetector.setLevel(Level.DISABLED);
If it does not work, try using this:
Код:
if (ResourceLeakDetector.isEnabled())
            ResourceLeakDetector.setEnabled(false);
Ответ
#5
PISTOLA Написал:Try this code:
Код:
ResourceLeakDetector.setLevel(Level.DISABLED);
If it does not work, try using this:
Код:
if (ResourceLeakDetector.isEnabled())
            ResourceLeakDetector.setEnabled(false);
Thx but i need to fix java leak not just stop LeakDetector , i enabled it to where is the leak to stop it cause many crashes ,i need some help to fix it PLZ

@PROGRAMMATOR @Awiion
Ответ
#6
There are 2 ways:

1. Use this after all read operations in the try {} finally{}

Код:
finally {
ReferenceCountUtil.release(msg);
}

2. Use .slice ()

Код:
ByteBuf bb = msg.content().slice();
Ответ
#7
DarkSkeleton12 Написал:There are 2 ways:

1. Use this after all read operations in the try {} finally{}

Код:
finally {
ReferenceCountUtil.release(msg);
}

2. Use .slice ()

Код:
ByteBuf bb = msg.content().slice();

THX , I will try this fix and I will inform you with the results , but I have Another problem is the disappearance of channels from the servers after running the server for a period of time or the entry of a number of players, and this is one of the worst problems that meet me
Ответ


Возможно похожие темы ...
Тема Автор Ответы Просмотры Последний пост
  UDP3 POSITION ERROR Comandante9901 13 5,337 10-10-2018, 09:20 AM
Последний пост: ChunkyHunt
  help me please UDP3 Event Position Error bmzproject 14 3,951 05-24-2018, 05:31 AM
Последний пост: PISTOLA
  Help me please UDP3 error bc.log P2P_SUB_HEAD_USER bmzproject 0 1,374 03-25-2018, 06:04 PM
Последний пост: bmzproject
  help udp 3 error barte 1 1,564 02-03-2018, 06:35 PM
Последний пост: blowstom
  [Error PXSD] В чем проблема? немогу понять. Codex1to 0 1,817 12-17-2017, 07:49 PM
Последний пост: Codex1to
  Shop Tag error Yusqa 2 1,508 11-24-2017, 05:22 PM
Последний пост: Yusqa
  маленткая производительность сервер Java slawa560 11 2,966 08-10-2017, 11:57 PM
Последний пост: Sojang
  i have this error clients connection TomCodder 2 1,731 08-07-2017, 06:43 PM
Последний пост: TomCodder
  Point Blank BR - Server Souce JAVA XJhonny 1 2,552 12-23-2016, 08:55 AM
Последний пост: djnansr
  [HELP ME] Error ID yGGhz 0 935 12-23-2016, 07:37 AM
Последний пост: yGGhz

Перейти к форуму:


Пользователи, просматривающие эту тему: 1 Гость(ей)