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

Anjan Baradwaj picture Anjan Baradwaj · Sep 17, 2016 · Viewed 17.3k times · Source

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.

Answer

Nicolas Filotto picture Nicolas Filotto · Sep 17, 2016

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.