June 1, 2007 23

Eclipse and memory settings

By Max in Uncategorized

Updated 03.08.07: eclipse.ini is sensitive to which line break is used. See Eclipse bug#198823

Many users seem to have problems with running out of memory when using Eclipse 3.2 in combination with additonal plugins such as those from JBoss Tools or even Eclipse WTP.

For those who just want the solution scroll down to the bottom, you can skip my “rant” about it.

The Problem

Eclipse default memory settings (at least for Eclipse 3.2) is to run with the following memory settings specified in its eclipse.ini file:

-vmargs
-Xms40m
-Xmx256m

This is ok for most users, but users can tweak these settings by editing eclipse.ini or via the command line, e.g.

eclipse -vmargs -Xms128m -Xmx512m

This would give some more room for extra many open projects and/or using plugins that might need additional memory (e.g. query results when running HQL via Hibernate Tools).

So why am I blogging about this ?

Well, it turns out that the combination of a eclipse.ini’s weird syntax and Sun JVM’s ‘alternative’ memory handling can give alot of headache.

Eclipse.ini

eclipse.ini is a configuration file that is located in the root of your Eclipse installation which is used as the default arguments passed to Eclipse.

This is all nice, but it is so easy to make it have zero effect by doing what makes the most sense, namely putting all the arguments on a single line in your eclipse.ini:

-vmargs -Xms128m -Xmx512m

The above line is simply ignored (or just not parsed correctly) by eclipse and hence the JVM is just started with the Sun VM default memory settings and the user thinks everything is fine.
The *correct* way of using eclipse.ini is to put each command line argument on individual lines:

-vmargs
-Xms128m
-Xmx512m

The best way to know if your command line arguments actually has been passed in correctly is to go to Help/About [Product Name] and click “Configuration Details” and check that the property “eclipse.vmargs” contain the values you expected.

This is expected and *correct*:

eclipse.vmargs=-Xms512m
-Xmx512m
-jar
/opt/eclipse32-3.2.2/startup.jar

This is *not*:

eclipse.vmargs=-jar
/opt/eclipse32-3.2.2/startup.jar

And that is exactly what happens when you put everything on one line in .eclipse.ini, so be careful!

Sun JVM PermGen

Sun JVM’s has a concept of PermGen space that is a *seperate* allocated memory region that is used for e.g. allocating classes. This is actually the memory region most people have issues with and not so much the normal heap space, but as a normal user one have a hard time realizing this when eclipse (or rather the jvm) just says “Out of Memory” or simply just crashes.

The solution for this is to add a MaxPermSize value to the vmargs. e.g. I normally use -XX:MaxPermSize=128m to make sure I don’t run out of PermGen space.

The Solution

*shameless plug*: Get Red Hat Developer Studio when it is relased which does this automatically for you, or…

Increase the memory settings via command line or eclipse.ini:

Command line

eclipse -vmargs -Xms128m -Xmx512m -XX:MaxPermSize=128m

Eclipse.ini

The trick is to remember each argument has to be on seperate lines:

-vmargs
-Xms128m
-Xmx512m
-XX:MaxPermSize=128m

Other solutions

Use a JVM that uses the normal heap for PermGen-like allocations (that is any non-Sun JVM AFAIK)
or help out with reducing the memory footprint of your favorite plugins by running them through a profiler and report found issues or possibly even contribute patches to the Jira :)

Related links

Igor’s blog about using jconsole to debug memory issues with Eclipse
Sun blog with nice explanation of PermGen and what might cause it in user code
Eclipse Program Launcher documentation
JBoss Tools/RHDS forum post that made me want to write this blog

23 Responses to “Eclipse and memory settings”

  1. Steve says:

    Hi,

    If the problem occurs when you are running the JBoss apache server perspective then the problem is not related to the eclipse.ini settings. When you first add your server you will have to define the JDK to be used and it is here that you can set the -Xms and -Xmx (and PermGen) settings for the chosen JVM. Each server runs in it’s own JVM and can be configured in isolation to the eclipse javaw process.

    Hope this helps someone :)

    Steve K

  2. Gautam says:

    I came here searching for memory related options for eclipse and found a lot more things on this site.

    I’ve bookmarked this site as I have a lot to read and get from here :) ..

    Btw, congrats on moving into your new house.

    Gautam

  3. Aryen says:

    Hi there,

    Your blog has clarified a lot to me! It was basically the only one which explains how to check whether the vmargs were read or not by Eclipse.

    So, despite all my changes on eclipse.ini, on Help->About->Configuration I still read eclipse.vmargs=-jar. Even running eclipse by command line (using the example you gave) keep generating the same result, as if it’s ignoring the vmargs no matter what.

    I eliminated all the empty lines and blank spaces, I tried to put the options in a different order, etc. It simply keeps ignoring. Concerning the Eclipse bug#198823, I believe is not the case here, because I’m working under Linux (openSuse) all the time – therefore eclipse.ini was never edited under Windows.

    So, my doubt is: all your comments and instructions are only valid for Eclipse under Windows? Can it be that Eclipse is actually reading the ini file though I can’t confirm it via Help->About…?

    Thanks.
    Aryen

  4. Alexander says:

    Thanks Steve for the valuable comment. I have been going nuts because my server was always out of heap memory while being run through Red Hat Developer Studio.

    But now, I know that the JVM has to be configured in RHDS… :)

    Thanks again.

  5. Max says:

    We added default arguments to the JBoss launch to have more permgen space; so now it should be able to do more hotdeployments outofthebox.

  6. Pete Muir says:

    If you are using Mac OS X, and launch eclipse using the Finder, the eclipse.ini in eclipse folder doesn’t have any effect. You need to open the Eclipse package (right click, show package content), open the Max OS folder, and edit the eclipse ini located there.

  7. Max says:

    yes – mac osx bundles things differently just to be different ( and annoying :)

  8. LK says:

    Hi, I have 9GB of main memory and I am wondering what is the maximum memory I can assigned to Eclipse?

    This is the content of my eclipse.ini:

    -showsplash
    org.eclipse.platform
    –launcher.XXMaxPermSize
    512m
    -framework
    plugins\org.eclipse.osgi_3.4.0.v20080605-1900.jar
    -vmargs
    -Dosgi.requiredJavaVersion=1.5
    -Xms40m
    -Xmx512m

    I tried to change XXMaxPermSize and -Xmx to 1g or 2g but it gives error when I tried to launch eclipse :(

    Hope you can help me out, thanks a lot!

  9. Kriley says:

    Thank you so much for this clear explanation of eclipse memory settings. I looked before when I was having out of memory problems and got wrong information. This should be made available in the eclipse faq or wiki. Thanks again!

  10. Alexander Jesse says:

    -XX:MaxPermSize=128m gives errors on startup
    -XX:MaxPermSize128m is correct

  11. Davis Nguyen says:

    Hi,

    Have you tried this?

    showsplash
    org.eclipse.platform
    -framework
    plugins\org.eclipse.osgi_3.4.0.v20080605-1900.jar
    -vmargs
    -Dosgi.requiredJavaVersion=1.5
    -Xms40m
    -Xmx512m
    –launcher.XXMaxPermSize
    512m

    Put –launcher.XXMaxPermSize value to the end of the eclipse.ini file

  12. Rodrigo Pinto says:

    try:

    -XXMaxPermSize=1024m
    -Xmx1024m

  13. Dmitri Vassiliev says:

    Just wanted to point out a minor inconsistency:

    When you say the Configuration Details should say:

    This is expected and *correct*:

    eclipse.vmargs=-Xms512m
    -Xmx512m
    -jar
    /opt/eclipse32-3.2.2/startup.jar

    I think you actually meant:

    eclipse.vmargs=-Xms128m

    since that is what you set it to.

    :P

  14. Kory Lovre says:

    Hi Xam,

    Subject – .ini file name must match the .exe file name and
    not all versions of eclipse require separate lines for .ini.

    Thanks for the info – it was great. I am running Eclipse Ganymede version 3.4.2 on a Windows XP box. The command line solution worked great for me but when I tried to add the commands to my eclipse.ini file they were never picked up – verifying the changes were made the way you indicate in your helpful solution. As it turns out I had changed the name of my eclipse.exe file to eclipse-3.4.2.exe. Thus, per

    http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.platform.doc.user/tasks/running_eclipse.htm

    the init parameters will be read from a corresponding .ini file called eclipse-3.4.2.ini or you can specify a particular file name using the command

    –launcher.ini (Executable) NEW
    the location of the product .ini file to use. If not specified the executable will look for a file beside the launcher with the same name and the extension .ini. (ie eclipse.exe looks for eclipse.ini, product.exe looks for product.ini)

    So, when I made this change and started Eclipse nothing happened – eclipse did not start up at all (my file had the commands on separate lines as you indicate in your solution). I changed my .ini file to be on one line and wham – Eclipse started just fine and the init parameter I had set in the .ini file were read in just fine.

  15. Spel says:

    Ahh thanks, I’ve been looking for a solution.

  16. Rob says:

    It is really important that you rename your .ini file if your executable is not called “eclipse”. The changes will not be picked up otherwise.

  17. Dárcio Nuno says:

    I had a problem about OutOfMemoryError because of the Eclipse and I read this article but the suggest didn’t solve. I found another solution in the net and I am going to share with you.
    On Eclipse select the menu Window>>Preferences>>Java>>Installed JREs

    Select the version that you use and click on the button Edit

    In field “Default VM Arguments” put for example:
    -Xms512m -Xmx1g

  18. Max says:

    Darcio, that works too but has the disadvantage that any Java App you run will (potentially) use that much memory. Just something to be aware of.

  19. Ric. says:

    Many thanks Pete Muir for your Mac Os X hints!! :-)

  20. [...] is a decent amount. You can go with less, or more depending on how much free memory you have. See here for more details on Eclipse memory [...]

  21. Tom Koenig says:

    Thanks. Appreciate the solution and the background. Fixed my problem and helped tie things together.

  22. Carlos Roberto says:

    I really wonder why these problems started with me now that I’m using windows 7, last week with Windows XP I had no problems at all (I got 2GB of Ram – before opening Eclipse I have 1GB free ) and this Eclipse WTP of mine is just the same as the other one (Copied and pasted the its folder), besides I got stupid projects in it, I mean, just have training and basic stuff so no real projects to cause such problems.

    * Using the lastest JDK though

  23. Max says:

    if the latest JDK is JDK6u20 then upgrade since u20 made Eclipse think it was no longer needed to pass the permgen flags to the VM since it was no longer called “Sun” but an “Oracle” VM.

Leave a Reply