#StackBounty: #java #spring-boot #out-of-memory #heap-dump #java-heap Java Heap Dump : How to find the objects/class that is taking mem…

Bounty: 50

I found that one of my spring boot project’s memory (RAM consumption) is increasing day by day. When I uploaded the jar file to the AWS server, it was taking 582 MB of RAM (Max Allocated RAM is 1500 MB), but each day, the RAM is increasing by 50MB to 100 MB and today after 5 days, it’s taking 835 MB. Right now the project is having 100-150 users and with normal usage of Rest APIs.

Because of this increase in the RAM, couple of times the application went down with the following error (error found from the logs):

Exception in thread "http-nio-3384-ClientPoller" java.lang.OutOfMemoryError: Java heap space

So to resolve this, I found that by using JAVA Heap Dump, I can find the objects/classes that are taking the memory. So by using Jmap in the command line, I’ve created a heap dump and uploaded it to Heap Hero and Eclipse Memory Analyzer Tool. In both of them I found the following:

1. Total Waste memory is: 64.69MB (73%) (check below screenshot)

enter image description here

2. Out of these, 34.06MB is taken by Byte [] array and LinkedHashmap[] (check below screenshot), which I have never used in my whole project. I searched for it in my project but didn’t found.

enter image description here
3. Following 2 large objects taking 32 MB and 20 MB respectively.

1. Java Static io.netty.buffer.ByteBufUtil.DEFAULT_ALLOCATOR

2. Java Static com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.connectionFinalizerPhantomRefs` 

enter image description here

So I tried to find this netty.buffer. in my project, but I don’t find anything which matched with netty or buffer.

Now my question is how can I reduce this memory leak or how can I find the exact memory consumption objects/class/variable so that I can reduce the heap size.

I know few of the experts will ask for the source code or anything similar to that but I believe that from the heap dump we can find the memory leak or live objects that are available in the memory. I am looking for that option or anything that reduces this heap dump!

I am working on this issue for the past 3 weeks. Any help would be appreciated.
Thank you!

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.