Before you can prevent OutOfMemoryErrors you must understand why and when they are thrown. Only then can you try to remedy them. This remedy may be in code, or by changing / adding flags when you start the JVM. Execute "java -X" (without the quotes) to see some nice flags, and you'll find at least one that could be useful. Hint: the default maximum amount of heap memory a (client) JVM can use is 64MB.
OutofMemory is something which can happen at any place, so to avoid them one has profile the application using profiling tools available in the market.
One should find out the places where memory is not released & try to fix them
Application should not hold the objects if they are not required
posted 8 years ago
The moustache of a titan! The ad of a flea:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop