Java/Tomcat heap size question-Collection of common programming errors

To resolve these issues you need to do performance testing. This includes both CPU and memory analysis. The JDK (6) bundles a tool called VisualVM, on my Mac OS X machine this is on the path by default as “jvisualvm”. That’s free and bundled, so it’s a place to start.

Next up is the NetBeans Profiler (netbeans.org). That does more memory and CPU analysis. It’s free as well, but a bit more complicated.

If you can spend the money, I highly recommend YourKit (http://www.yourkit.com/). It’s not terribly expensive but it has a lot of built-in diagnostics that make it easier to figure out what’s going on.

The one thing you can’t do is assume that just adding more memory will fix the problem. If it’s a leak, adding more memory may just make it run really badly a bit longer between restarts.