Oct 3, 2011

Out of memory error in Eclipse

If you use sun's JVM along with Eclipse you will undoubtably run into memory issues, especially if you run JBoss tools or WTP.

So lets get real here, even at 3rd world 'cheap genius' rates it can be shown that in a matter or just a few hours you can recover the cost of 4Gb of Ram. At time of writting in the USA 8Gb of Ram for a laptop (using DD3 SoDIMS) will set you back less than $45.

The default memory setting for Eclipse are absurd, the heap memory starts at 40mb and maxes out at 256mb. All you need to do is to set the maximum to any value that is reasonable for your environment. For a modern development workstation which should be equipped with at least 4gb of RAM you should be comfortable setting the maximum at least at 512mb if not 2gb. I run 8gb RAM, so I am more than happy to set the value to 2gb.

Now, keep in mind that Eclipse is not going to use 2gb, or rather it is very unlikely that will ever occur, and if it does it most probably points to a bug somewhere. After all, its happy to do its thing most of the time with a maximum of just 256mb right? This is just the maximum value. In a multi-generational garbage collection environment, you will not use this much memory as the trigger for garbage collections is generally the act of extending memory - which occurs only when you run out of memory. The pattern therefore is ...

1. Request some memory
2. Fail to satisfy this memory request
3. Invoke Garbage Collector
4. Repeat attempt at memory request
5. If this fails to satisfy the request, increase memory

The above can be considered 'paraphrased and simplified' and is meant to assist in the conceptual understanding of what is going on when the JVM requests more physical memory to add to its heap. At each major release of the JVM the details and rules surrounding Garbage Collection and memory allocation change a little as the authors try to improve the balance between memory consumption and performance. Its never too productive to know the details of the Garbage collection too intimately, lest we design our code too reliant on a specific algorithm. However, you can rely on the knowledge that many very intelligent developers have and will continue to strive to ensure the best balance between memory and performance. All of this means that you are very safe in increasing your maximums well beyond the default settings.

To fix your issue, edit the Eclipse.ini file found in your Eclipse distribution. Mine looks like this...

eclipse.ino

0 comments:

Post a Comment