To solve these problems, you must perform performance testing. This includes processor and memory analysis. JDK (6) bundles a tool called VisualVM, on my Mac OS X machine this is by default called "jvisualvm". It's free and bundled, so this is the place to start.
Next is NetBeans Profiler (netbeans.org). It does more memory and processor analysis. It's also free, but a little trickier.
If you can spend money, I highly recommend YourKit (http://www.yourkit.com/). It is not very expensive, but it has many built-in diagnostics that make it easy to find out what is happening.
The only thing you cannot do is assume that simply adding more memory will fix the problem. If this is a leak, adding more memory may cause it to work very much longer between reboots.
source share