not clearing heap memory - threads allocated and not releasing netty latest version
See original GitHub issueExpected behavior
Heap memory should clear after processing messages
Actual behavior
Keep piling up memory not releasing my threads still serving for network messages for checking connections.
Steps to reproduce
keep checking network connectivity and processing messages.
Minimal yet complete reproducer code (or URL to code)
server : ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(“decoder”, new Decoder()) .addLast(“encoder”, new Encoder()) .addLast(group, new Handler());
}
}).option(ChannelOption.SO_BACKLOG, 1024)
.childOption(ChannelOption.TCP_NODELAY, true)
.childOption(ChannelOption.SO_KEEPALIVE, true);
List<Integer> ports = Arrays.asList(8080,8081); channels = new ArrayList<>(ports.size()); for (int port : ports) { Channel serverChannel = bootstrap.bind(port).sync().channel(); channels.add(serverChannel); }
decoder : public class Decoder extends ByteToMessageDecoder {
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf byteBuf, List<Object> out) throws Exception {
---- business logic to read – add object to out. out.add(msg); } } handler : public class Handler extends ChannelInboundHandlerAdapter {
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { –business logic– ctx.writeAndFlush(msg); } }
Encoder :
public class Encoder extends MessageToByteEncoder<Object> {
@Override protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) {
–business logic –
out.writeBytes(msg.getBytes());
} }
Netty version
4.1.45.Final
JVM version (e.g. java -version
)
Adopt OpenJDK 11
OS version (e.g. uname -a
)
Linux
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (6 by maintainers)
Top GitHub Comments
Also alternative you can configure the
PooledByteBufAllocator
to only pool direct memoryI think you will need to share more code and also ensure there are no buffer leaks detected.