how to test netty memory leak

2019-04-29 17:28发布

问题:

I add -Dio.netty.leakDetection.level=ADVANCED for leak detecting on production. And there are some logs:

ERROR io.netty.util.ResourceLeakDetector - LEAK: ByteBuf.release() was not called before it's garbage-collected. See http://netty.io/wiki/reference-counted-objects.html for more information. WARNING: 4 leak records were discarded because the leak record count is limited to 4. Use system property io.netty.leakDetection.maxRecords to increase the limit. Recent access records: 5

Does it means it must will happen memory leak?

I want to test it on local environment, so I set -Dio.netty.leakDetection.level=PARANOID, but there are no the above memory leak records logs.

回答1:

To detect leak on my development environment, I have reduce the heap size to 12 MB with this vm argument: -mx12m

Now with this, Netty is able to detect some leaks.



回答2:

The log means that you have a memory-leak, so yes there is a leak. You can either configure leak detection via the system property (as you did) or via ResourceLeakDetector.setLevel(...).

That you are not able to see the leak on your local machine may mean that you not see the same "allocation" patterns as on the prod server.