Java memory leak

Has anyone used Eclipse's memory manager to detect memory leaks in java codes? Can anyone recommend a good place to find information on using the memory manager? I read something on the Internet, it says that I need to run the program until it crashes (due to a memory error), which will generate a crash report. Then use the memory manager to open this report to check where a memory leak might occur. Is this how everyone uses a memory manager?

+4
source share
6 answers

Although - XX: + HeapDumpOnOutOfMemoryError may be useful, my current workflow for using Eclipse Memory Manager is:

  • Usually run the program
  • Wait until the memory gets out of control.
  • Run jmap : jmap -dump:format=b,file=dump.hprof <PID>
  • Open the hprof file in EMM.

Usually I start working with a histogram and representations of the dominant tree to see if something seems to be due to a hit, and then turn around from there.

VisualVM can be useful, but it seems much less efficient than EMM when working with a heap dump (EMM caches a lot of information about loading a heap dump). Netbeans Profiler is good for getting distribution locations and for profiling time.

+2
source

Perhaps the easiest way is to run your program under HProf (included as standard with the JVM) for some time, and force output. The conclusion of HProf, we hope, will give you some recommendations. memory leak.

Unlike the Eclipse memory debugger (which I only know from what you are writing), you can collect statistics from anywhere at runtime.

+2
source

this suggests that I should let the program work until it crashes (due to a memory error), which creates a crash report.

I don’t think it’s true - you won’t get the dump file when OutOfMemoryError (I would bet that the author confuses this problem with some kind of JVM error that will cause the main dump to be saved).

The best procedure is to grab a bunch of heaps using jmap ; this will output the heap contents to a binary file (commonly known as an hprof file). Then this file can be analyzed using any number of analyzers:

  • jhat - A sun tool that analyzes an HPROF file, launches an embedded web server, so you can analyze a bunch through a web browser / view reports. I found this to be very slow for large heaps.
  • VisualVM - Awesome debugging / troubleshooting tool bundled with JDK. Among other things, it can also be used to dump a heap of any running process, as well as a thread dump. I found it very slow to load large hprof files, though.
  • Eclipse Memory Analyzer is an Eclipse plugin that can generate hprof files.

I highly recommend using the plug-in for Eclipse, since it loads very quickly large (> 500MB) heaps of dumps (per minute), produces useful reports, supports a query language with complex logic, etc.

+2
source

This page explains how to work with jvm heap dumps. Jhat is a simpler, albeit less graphical way to work with heaps, but you can also upload the same dump files to eclipse's memory manager. You can also get some information from jvisualvm if you use current (1.6) jvm.

+1
source

I usually prefer to profile applications using Profiler NetBeans. You can pretty easily see which objects flow and where they are created in most cases. There are probably several other tools that will do this as well, but I know that the NetBeans profiler works well and is easy to use.

0
source

You can try using Jprobe . You can control your application and view objects as they are created. In addition, it will help to analyze which objects are not going to collect garbage and will be pointers for moving.

Although it is not free, but I remember that it comes with a trial license, so check this out.

0
source

All Articles