4

I've been testing my webapp locally on my pc and monitoring it with VisualVM. I recently also started using JMeter, as it was suggested that I should do some load testing since I suspected that I have a slow memory leak somewhere.

Today my webapp finally threw the OutOfMemory exception. I had the HeapDumpOnOutOfMemoryError and HeapDumpPath params set in case this ever happened. A heap dump file was generated.

I opened this file (java_pid2760.hprof) in VisualVM, and honestly, I don't understand how I'm supposed to be able to pinpoint the culprit of this memory leak...

How do you use VisualVM to analyze a heap dump and find the class/instance that is generating the memory leak?

trincot
  • 317,000
  • 35
  • 244
  • 286
katura
  • 2,177
  • 14
  • 39
  • 48
  • possible duplicate of [How do I analyze a .hprof file?](http://stackoverflow.com/questions/185893/how-do-i-analyze-a-hprof-file) – meriton Feb 07 '11 at 18:30
  • also related: http://stackoverflow.com/questions/2064456/how-much-memory-does-jprofiler-need-to-analyze-a-heap-dump-of-size-x , http://stackoverflow.com/questions/1795778/are-there-tools-to-analyse-large-java-heap-dumps-without-loading-the-complete-hpr , http://stackoverflow.com/questions/2422868/how-to-analyze-heap-dumps – meriton Feb 07 '11 at 18:31
  • My question was aimed at using VisualVM to pinpoint a memory leak. This product that comes with the JDK should be able to, no? I appreciate the suggestions to use other types of software, but since I have VisualVM, I'd like to stick with it. Has anyone used VisualVM to find a memory leak? – katura Feb 07 '11 at 19:26

2 Answers2

3

Here's a couple of links I found helpful when debugging memory leaks:

http://olex.openlogic.com/wazi/2009/how-to-fix-memory-leaks-in-java/

http://www.ibm.com/developerworks/rational/library/05/0816_GuptaPalanki/

Edit:

You might also want to try: http://rejeev.blogspot.com/2009/04/analyzing-memory-leak-in-java.html

jwir3
  • 6,019
  • 5
  • 47
  • 92
1

Using VisualVM to analyze heap dumps and pin-point memory leaks is not easy, and I wouldn't recommend using this tool if this is your first time working on this type of problem. Consider downloading HPjmeter and letting it do the work for you.

After opening the dump file, select the Sorted Reference Graph Subtree option. This will show you all of the objects in your webapp sorted by size. In most memory leak scenarios, you are leaking one type of Object that balloons over time in the heap. HPjmeter will help you identify this case quickly.

Amir Afghani
  • 37,814
  • 16
  • 84
  • 124
  • @ Amir Afghani - I don't think I can use HPjmeter since I don't have an HP system. That software is for use on HP-UX 11i systems. – katura Feb 07 '11 at 18:05
  • Yes you can. The HPjmeter console is a Java program. You can run it on any system. – Amir Afghani Feb 07 '11 at 19:51
  • Failed to install it on Windows 8.1. After googling found claims that it's incompatible with this version of Windows. – Ilya Serbis Feb 10 '16 at 19:38