question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

not clearing heap memory - threads allocated and not releasing netty latest version

See original GitHub issue

Expected 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. image

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:closed
  • Created 3 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
normanmaurercommented, May 11, 2020

Also alternative you can configure the PooledByteBufAllocator to only pool direct memory

0reactions
normanmaurercommented, May 25, 2020

I think you will need to share more code and also ensure there are no buffer leaks detected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

buffer not releasing memory. · Issue #10310 · netty/netty · GitHub
my application - netty server needs to run continuously with out closing client connection and keep serving messages 24/7.
Read more >
netty - java heap memory management insufficient memory
1 Answer 1 · the JMC figure I updated has netty receiver threads block number 160,000 level, and is accumulating. · I don't...
Read more >
Troubleshooting Problems With Native (Off-Heap) Memory in ...
This tutorial demonstrates troubleshooting methods for Native Memory in Java apps, including I/O threads, OutOfMemoryError, Native memory ...
Read more >
Understanding Memory Leaks in Java - Baeldung
A Memory Leak is a situation where there are objects present in the heap that are no longer used, but the garbage collector...
Read more >
Troubleshooting OutOfMemoryError: Direct buffer memory
As we said, the Direct Buffers are allocated to native memory space outside of the JVM's established heap/perm gens. If this memory space ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found