Debugging Java Memory Leaks

Hello world, I am working late on the Microsoft SQL Server 2005 JDBC Driver. Very fun job, but the stress tests are killing me. I'm trying to run some stress tests where the JDBC driver is under heavy load for long periods of time and what I find is that working set memory keeps ramping up forever in the Java VM.

Well, my specialty is digging into memory issues, at least in the Windows world I know how memory works, but I am very rusty in the Java VM world, working at Microsoft for many years.

Anyway, I found a killer gadget from IBM that makes my life very easy. Check it out sometime if you are a debugging geek like me.

What you do is get the latest IBM VM you can find first, and use this to run your tests. I'm using the IBM VM that comes with trial developer version of WebSphere I'm testing some things on. Search the Internet for HeapRoots205, it's up on the IBM site as well. This tool totally rocks. It's like a memory explorer for Java memory dump files. What you do is start the VM with flags so you can dump memory. There are even flags you can use that will allow you to dump memory when you press ctrl-c (see for example for a listing of the cool flags). Run your stress from a console app and periodically hit the ctrl-c or just set a memory limit (use -Xmx200m Java Vm flag for example to limit total memory to 200MB) and let the VM run out of memory and it will dump. Then use the HeapRoots205 tool to explore the dump file.

I wrote a little batch file that you pass in the heap dump file name to load it up:

"C:\Program Files\IBM\WebSphere\AppServer6\java\bin\java.exe" -Xbootclasspath/p:svcdump.jar -jar C:\Stress\HeapRoots205\HR205.jar -v -i %1

I've tried some other tools but HeapRoots205 appears to be the best out there I can find.

I am a bit spoiled by .NET framework and how easy it is to use the debugger extension sos and dig through memory dumps using !dumpheap etc. The Java folks need to write some better tools for examining these dump files they are a bit primative right now. Perhaps I am missing something obviously more cool out there (this is probably the case!). If anyone out there knows of a cooler memory debugging tool for Java let me know.