How to find memory leaks using visualvm

54,146

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?

Share:
54,146
IAmYourFaja
Author by

IAmYourFaja

my father is a principal at burgoyne intnl and got me this job programming lisp and development. I aspire to unittesting with a concentration in mobile platforms.

Updated on June 10, 2020

Comments

  • IAmYourFaja
    IAmYourFaja about 4 years

    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.

    • Jivings
      Jivings over 12 years
      Have you tried running FindBugs over the source? I find that pretty effective at identifying code that could cause memory leaks.
    • IAmYourFaja
      IAmYourFaja over 12 years
      Thanks for the suggestion - but two things: (1) I've been told over and over again that FindBugs is good for NullPointerExceptions but not memory leaks, and, more importantly, (2) I really want to get familiar with jvisualvm, so unless it is clearly not the right tool for this job, I'm interested to see how it is used as a diagnostic tool. Thanks again for the good suggestion though!
    • Dante WWWW
      Dante WWWW over 12 years
      One little thing: Tools/Plugins/Available Plugins -- install Visual GC -- the plugin shows better graph of your heap memory and GC status.
  • Chin
    Chin over 7 years
    MAT can also take a heap dump itself without VisualVM
  • Jouni Aro
    Jouni Aro about 3 years
    The article that was maybe linked here is nowadays available at dzone.com/articles/…