views:

277

answers:

11

I have a java application that runs out of memory, but I have no idea which code is allocating the memory. Is there an application with which I can check this? I use Eclipse.

+3  A: 

You want a Profiler.

Here is a comprehensive list.

MarkPowell
+3  A: 

I've had great success with JProfiler

http://www.ej-technologies.com/products/jprofiler/overview.html

yankee2905
+1  A: 

Yourkit is a great tool that I've used on MANY occasions to find and document performance issues. Eclipse with the TPTP framework can be used to do this as well. It also works well against remote application servers (you need to enable profiling agents and turn on remote debugging in the JVM), but it lets you run profiling against pretty much any J2EE environment.

Chris Kaminski
+1  A: 

You need to use a memory profiler. You can either use Sun's JVM Tool Interface or a third-party profiler like JProfiler. Eclipse also has profiling tools, called the Test & Performance Tools Platform (TPTP).

rob
+8  A: 

Since you use eclipse I would recommend the Eclipse Memory Analyzer plugin. This tool works great, and will even provide a report with some likely leak suspects. I have looked at over 1G heap dumps with this with no problems. I just use jconsole included with the JDK to get the dump.

Also here is a great blog on using the tool, by one of the authors of the tool.

This is also free.

broschb
+1: nice tool... do you know if there's any restriction concerning the jvm version or the kind of jvm ?
LB
I'm not sure on the jvm restriction i have used it in 1.5 and 1.6. But I have had a hard time getting heap dumps with older versions of java, which the tool relies on.
broschb
+2  A: 

I'm sure everyone has their favorite, but I recommend Netbeans.

Seth
+4  A: 

VisualVM is a visual tool integrating several commandline JDK tools and lightweight profiling capabilities. Designed for both production and development time use, it further enhances the capability of monitoring and performance analysis for the Java SE platform.

And it is included in JDK.

cetnar
+1  A: 

For fast profiling or if you don't use Eclipse or older versions of the jvm, hprof is a decent alternative. (I just add that as a reference.).

LB
One important advantage of hprof is that it has minimal dependencies: part of JDK, and no GUI. So in a pinch you can easily install-).
sleske
A: 

I had to find the source of a memory leak that produced a 2.6G heap dump the other day. Jhat required an unbelievable 20G heap size to crunch through it without crashing. Eclipse memory analyzer did it in under 10G. That said, I found both tools useful, but would recommend memory analyzer first for more efficient use of memory and being more easy to use.

I was pretty amazed by the amount of memory used but I can assure you if I used less I head OutOfMemory errors.

Ben
A: 

I've spotted memory leaks using HP Diagnostics Profiler free evaluation (unlimited for 5 threads). It allows to trace memory allocation and do heap analysis in a visual, easy way.

antispam
A: 

Try YourKit Java profiler It shows objects with biggest retained sizes (dominators) http://www.yourkit.com/docs/80/help/biggest%5Fobjects.jsp

--serge

Serge