source: http://blog.seancassidy.me/better-java.html
Memory leaks happen, even in Java. Luckily, there are tools for that. The best tool I've used to fix these is the Eclipse Memory Analyzer. It takes a heap dump and lets you find the problem.
There's a few ways to get a heap dump for a JVM process, but I use jmap:
$ jmap -dump:live,format=b,file=heapdump.hprof -F 8152 Attaching to process ID 8152, please wait... Debugger attached successfully. Server compiler detected. JVM version is 23.25-b01 Dumping heap to heapdump.hprof ... ... snip ... Heap dump file created
Then you can open the heapdump.hprof file with the Memory Analyzer and see what's going on fast.