Eclipse and OutOfMemory
I have run into the same problem that seems to be plaguing a number of other Eclipse users lately (http://www.jroller.com/page/phidias?entry=eclipse_running_out_of_memory, http://www-03.ibm.com/developerworks/blogs/page/JEE?entry=eclipse_out_of_memory). This problem was happening rarely for me running Eclipse 3.3M4, but it started happening to me at least 5 times an hour (if not more frequent) when I upgraded to Eclipse 3.3M6. This is nothing new for me. I have been using Eclipse since version 2.0 and have run into OOM errors before — although usually it was because I did something dumb like download a new version and forget to alter the heap size. (Just for fun, try running the old Motif version of Eclipse 2.0. Eclipse has really come a long way.).
I started searching around for fixes for the problem, but I wanted to understand what was going on since I log a lot of hours with Eclipse. I am running Eclipse 3.3M6 (I20070323-1616) on a 2.8GHZ P4 with 4GB of RAM under Windows Vista using JDK 1.5.09. The plugins I have installed are Mylar, Hibernate Tools, Subversive, WTP, and Spring IDE.
My first settings to change were the minimum heap size to 128MB (-Xms128m) and the maximum heap size to (-Xmx512m). I have seen some recommendations to set the minmum size to 512m. I would toggle Window -> Preferences -> General -> Show heap status to on first. Watch your heap usage and see what you normally trend at before setting it to a higher number. If you are only working with small to medium size projects, then you should be fine at that number. As a benchmark, I was able to take my heap up to 150M by running a Project -> Clean on both Spring and Hibernate’s source code at the same time, running it in the background, and opening other projects. I also checked out some large projects with Subversive and ran some standard tasks editting in Mylar. I am sure there are more heap intensive plugins that you are probably running, so best bet is to turn on the status and tweak later.
After verifying that did not fix the problem, I altered the PermSize and MaxPermSize parameters (-XX:PermSize=128m -XX:MaxPermSize=128m) to be 128M. This solved me problem I have now been running Eclipse happy for 7 hours without a crash. If you make these changes and are still having problems, use the -XX:+HeapDumpOnOutOfMemoryError setting to generate a heap dump (for more information on debugging heap dumps, go here and here.
Below is a screenshot I snapped using JConsole to show that my PermGen space does indeed trend over the default setting of 64m. The J2SE 5 version of JConsole did not seem to play nice with Vista, so this is attached to my 1.5.09 JVM using the JDK 6 version of JConsole.

Some other recommendations for fixing the problem include using IBM or JRockit to run Eclipse. Apparently, those JVMs have no concept of PermGen space and the PermGen data is stored directly on the heap. It is then subject to garbage collection like the objects stored in the heap. If I was starting an application from scratch, I would probably use JRockit but most of us are stuck with Sun’s JVM.
Off of the top of my head, I can probably name no more than ten options you can pass the JVM on the command line to configure garbage collection, JMX, system properties, etc. I have been working on J2EE applications for years and a company where we migrated applications from Java 1.2, 1.3.1, 1.4.2, and 1.5. I dealt with a lot of OOM errors in our web applications and did a decent amount of JVM tuning. Having said that, how many Eclipse users know that there are options that can be passed to the JVM for tuning? I would guess that there are a large number of users who have never dealt with tuning JVM parameters at all. Those same users probably also do not realize that there are other JVM options besides Sun’s JVM to choose from.
I was thinking about this as I was looking through this bug in Eclipse Bugzilla. Some of the comments on the bug suggest that this is an Eclipse problem, some of them suggest that it is a Sun problem. However, this is going to be a big annoyance for Eclipse users going forward unless someone fixes it. I do not see anything happening on the Sun side (nor am I sure that they can do anything without significantly changing their JVM), but it would be nice to see Eclipse either 1) present the user with a warning on the splash screen with a link to configuring their JVM properly for Eclipse 2) have a warning that goes off when the PermGen size get’s beloww 5%-10% with a help link on how to fix the problem.