Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to analyze heap data from .hprof file and use it to reduce memory leaks?

In recent times, I have encountered java.lang.OutOfMemoryError exception while running an application.

During one such instance, I was able to get the heap dump using jvisualvm.

I am able to open the .hprof heap dump file obtained from the heap dump using NetBeans 8.1 IDE but I am not aware of how to analyze the data dump. I'd like to know how to read the dump file and take corrective actions to reduce the out of memory exception from an application perspective.

like image 700
Anjan Baradwaj Avatar asked Sep 17 '16 09:09

Anjan Baradwaj


People also ask

How do I analyze a .hprof file?

In order to analyze the hprof files, there is a tool called Memory Analyzer(MAT) provided by SAP and IBM jointly.

How do you analyze heap memory?

Eclipse Memory Analyzer Tool ( MAT ) is used for analyzing heap dump files which contain objects in memory. Each heap dump file can be thought of as a snapshot in time and details the memory occupied by specific JVM threads.

How do you analyze a memory leak heap dump?

Using JMAT Tool to Analyze Heap Dump You can Scroll down under Overview tab and then click on Leak Suspects to find the details as shown in below screenshots to pinpoint the class responsible for OutOfMemoryError and the number of Objects that was created.

How do I read a heap dump file?

Open Eclipse MAT To open the heapdump, go to File > Open Heap Dump (Not Acquire Heap Dump) and browse to your heapdump location.


1 Answers

There are many ways to find the root cause of a memory leak, like using a profiler such as JProfiler and simply applying what is described in this great video. You could also have a look to Eclipse Memory Analyzer also know as MAT that will be able to analyze your heap dump and propose potential causes of your memory leak as you can see in this video (you can find more information about the Suspect Report here). Another way could be to use Java Flight Recorder by applying this approach. Or using JVisualVM using the approach described in this video.

like image 106
Nicolas Filotto Avatar answered Oct 12 '22 09:10

Nicolas Filotto