Reputation: 7562
I've managed to get a memory 'leak' in a java application I'm developing. When running my JUnit test suite I randomly get out of memory exceptions (java.lang.OutOfMemoryError).
What tools can I use to examine the heap of my java application to see what's using up all my heap so that I can work out what's keeping references to objects which should be able to be garbage collected.
Upvotes: 22
Views: 22493
Reputation: 13327
If you need something free, try VisualVM
From the project's description:
VisualVM is a visual tool integrating commandline JDK tools and lightweight profiling capabilities. Designed for both development and production time use.
Upvotes: 7
Reputation: 17302
This is a pretty old question. A lot of people might have started using IntelliJ since it was originally answered. IntelliJ has a plugin that can show memory usage called JVM Debugger Memory View.
Upvotes: 3
Reputation: 2624
Use the Eclipse Memory Analyzer
There's no other tool that I'm aware of any tool that comes close to it's functionality and performance and price (free and open source) when analysing heap dumps.
Upvotes: 2
Reputation: 7069
You can try the Memory Leak Detector that is part of the JRockit Mission Control tools suite. It allows you to inspect the heap while the JVM is running. You don't need to take snapshots all the time. You can just connect online to the JVM and then see how the heap changes between garbage collections. You can also inspect objects, follow references graphically and get stack traces from where your application is currently allocating objects. Here is a brief introduction.
The tool is free to use for development and you can download it here.
Upvotes: 0
Reputation: 56342
VisualVM is included in the most recent releases of Java. You can use this to create a heap dump, and look at the objects in it.
Alternatively, you can also create a heapdump commandine using jmap (in your jdk/bin dir):
jmap -dump:format=b,file=heap.bin <pid>
You can even use this to get a quick histogram of all objects
jmap -histo <pid>
I can recommend Eclipse Memory Analyzer (http://eclipse.org/mat) for advanced analysis of heap dumps. It lets you find out exactly why a certain object or set of objects is alive. Here's a blog entry showing you what Memory Analyzer can do: http://dev.eclipse.org/blogs/memoryanalyzer/2008/05/27/automated-heap-dump-analysis-finding-memory-leaks-with-one-click/
Upvotes: 30
Reputation: 30848
JProfiler worked very well for me....
http://www.ej-technologies.com/products/jprofiler/overview.html
Upvotes: 1
Reputation: 7562
If you're using a system which supports GTK you could try using JMP.
Upvotes: 0