views:

421

answers:

4

I am trying to pin down a memory leak problem for my standalone Java program that runs on unix. I have the port and params setup such that I can connect to it using JMX with JConsole or VisualVM already.

Those help a little but unfortunately it doesn't tell you where the memory has gone, it only tells you how much memory is used. I'm looking for a more detailed profiler to help me locate the objects that is eating up my memory. Anyone have any ideas? Preferably one that talks on JMX port so I don't have to reconfig the program. Thanks!

A: 

I looked at several and like YourKit the most.

It was by far the easiest to use and works great with JMX.

Eric J.
I just downloaded Yourkit and it doesn't work with JMX. It requires my standalone to do manual setup which is undocumented and very difficult!
erotsppa
I'm sorry that you could not get it working with JMX.
Eric J.
Can you give me pointers on how to connect with JMX? Is it not possible?
erotsppa
@erotsppa: After re-reading, I think I may be a bit confused exactly how you want to use JMX. We wrote an MBean to control profiling and gather results. If you mean communicate on the JMX port with the agent, you can select the port you want to use when launching the app but it would not use the JMX protocol, but rather then JVMPI protocol. Using JVMPI on its own port is accomplished with a java command line switch, with no need to change the app itself. Does that clear things up a bit? Sorry for the initial confusion.
Eric J.
A: 

The NetBeans Java Profiler supports profiling of remote JVMs. One can have NetBeans connect to the remote JVM using JMX.

A presentation available on the JavaPassion site provides a few pointers on how to get started.

Vineet Reynolds
A: 

Um... actually, VisualVM has an excellent memory profiler that can tell you not just which objects eat your memory, but also where they're (perhaps inadvertedly) referenced.

Just press the "Heap dump" button on the Monitor tab and be amazed!

Michael Borgwardt
Heap dump does not work for remote JVM
erotsppa
Hm, that is a shame. Can't you run VisualVM on the same machine?
Michael Borgwardt
in that case just use jmap from the command line to dump the heap, and then analyze it on any machine you'd like.
matt b
A: 

If the machine in question have the X11 client libraries installed, AND a ssh server which allows X11 forwarding, AND an X11 server running on your local machine (perhaps http://sourceforge.net/projects/xming/) AND you use a Sun Java 6u10 or later, you can ssh (with either -X or -Y) into the LInux box, and run jvisualvm there while showing its GUI-interface on your local machine.

Running on the same machine allows jvisualvm to attach directly to the running Java process instead of doing all kinds of configuration voodoo.

Thorbjørn Ravn Andersen