My good friend (and creator of Apache Wicket) Jonathan Locke just gave me a great tip. I was aware of the jmap utility, but didn’t know it could do this:
jmap -histo:live <pid>
Where <pid> is the process id of a Java process, and it will dump out all objects, starting with whichever is taking up the most memory.
The handy thing is that the Java process doesn’t need to have been started with any kind of special command line options, it will work with any running Java process.
I wish I knew this a few weeks ago while debugging a memory leak on a remote server…