Recently I had to analyse memory issues on the jvm and I found Tagtraum‘s GCViewer very useful. Java Performance Tuning has a great article on how to get up to speed very quickly with it. To elaborate a little – when you have memory issues such as out of memory or poor garbage collection you can turn on verbose gc output and direct it to a file using the following jvm arguments -verbose:gc -Xloggc:gc.out. Then once you have some gc output that output can be fed back into a gc viewer such as GCViewer to visualise it.
GC log output is not very human readable and so a viewer like this can be indispensable and very revealing about your application indeed. It can tell you for example that your application over a period of a few hours accumulated a heap usage of 1GB and then after a major gc lasting 4 seconds cut the heap down to 100MB. A couple of other tools that are also worthy of mention in this context are jconsole and visualvm (with the visualgc plugin installed) which also offer heap and gc visualisation.