Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find memory leaks using visualvm

I suspect we have a major memory leak in our ActiveMQ connection bridge - we're seeing typical memory leak patterns (app loads fine, slows down if it runs for prolonged periods of time or is restarted over and over again over short periods of time). I looked up modern best practices for finding Java memory leaks and a lot of developers seem to be abandoning traditional tools like jhat/jmap in lieu of the new(er) jvisualvm.

Upon launching this tool (and spending a few hours reading over its tutorial) I am able to take profiler snapshots for both CPU and memory.

I'm just sort of stuck at this point - how do I analyze these snapshots to identify the leak? There's a plethora of documentation out there as to how to use jvisualvm to produce snapshots, but very little documentation as to how to actually make sense of them.

Thanks in advance.

like image 533
IAmYourFaja Avatar asked Feb 06 '12 01:02

IAmYourFaja


People also ask

How do I find a visual VM memory leak?

In the client machine, open a prompt and type jvisualvm to open the VisualVM tool. To run a memory profiler on the application, we just double-click its name in the side panel. Now that we're all set up with a memory analyzer, let's investigate an application with a memory leak issue, which we'll call MemLeak.

How do I find a memory leak in 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.


1 Answers

Analysing memory leak using visualvm is not that easy. It has a tool/plugin called 'sampler'. This can be used to sample memory or cpu. You can take snapshot at regular interval and look for possible leaks. Here is some details on how to use it- Obtained from quick search

More effective way will be to get a heap dump (say when the application has slowed down or when OOM happens). VisualVM help you to take heapdump (using Heap Dump on Monitor tab)

This file can be analysed by MAT- Some details are here at How do I analyze a .hprof file?

like image 109
Jayan Avatar answered Oct 14 '22 20:10

Jayan