June 1, 2007 36

Eclipse and memory settings

By 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

  • Steve

    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

  • http://www.wishlost.com Gautam

    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

  • Aryen

    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

  • Alexander

    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.

  • Max

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

  • http://in.relation.to/Blloggers/pmuir Pete Muir

    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.

  • Max

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

  • LK

    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!

  • Kriley

    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!

  • Alexander Jesse

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

  • http://wiki.glassfish.java.net/Wiki.jsp?page=GlassfishPluginQA Davis Nguyen

    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

  • Rodrigo Pinto

    try:

    -XXMaxPermSize=1024m
    -Xmx1024m

  • Dmitri Vassiliev

    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

  • Kory Lovre

    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.

  • http://www.coolaspel.se Spel

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

  • http://edwards.sdsu.edu/labsite Rob

    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.

  • Dárcio Nuno

    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

  • http://blog.xam.dk Max

    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.

  • Ric.

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

  • Pingback: Installing and Configuring Eclipse | FlutterCode

  • Tom Koenig

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

  • Carlos Roberto

    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

  • http://blog.xam.dk Max

    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.

  • Marcus

    This post is solving you problems for sure.
    Pls approve. This is an excellent article with screen shots and will help many
    http://dinu.blog.com/2010/06/02/out-of-memory/

  • http://blog.xam.dk Max

    Marcus, your link just talks about how apps are launched *from* eclipse – not eclipse it self.

  • Stephan

    Spent over 2 days trying to solve out of memory issue with Eclipse JBoss plugin. Only thing worked for me is changing VM_ARGUMENTS value in .launch file (see below) while Eclipse is closed:

    ..\.plugins\org.eclipse.debug.core\.launches\JBoss 4.2 Runtime Server.launch

  • http://blog.xam.dk Max

    Stephan, easier if you just double click the server inside Eclipse and add the memory settings via the launch configuration.

    p.s. the external launch of Jboss does not have anything to do with the memory setting of what Eclipse is running with/under.

  • David

    I prefer to configure multiple shortcuts with different command line arguments. Like this i can allocate memory depending on the need of the current project i’m working on :

    http://www.java-tutorial.ch/eclipse/eclipse-memory

  • http://blog.xam.dk Max

    David, the data in eclipse.ini is just used as fallback; you can both have eclipse.ini for defaults and use command line arguments for specific cases.

  • http://www.popspel.se spel

    great! thanks for posting this..I have been looking around for a while

  • Pingback: Como ser um pouco mais produtivo utilizando Eclipse e JSF - Moacir R.F

  • Jurgen

    Wow, Oct 11 2011 and this still has to be fixed this way… thanks for sharing!

  • http://geckolandmarks.com Asmo

    Note for anyone working with eclipse.ini in Mac OS for the first time: The file is NOT in the same directory as the Eclipse-executable, it is found as a part of the Eclipse.app -package.

    http://wiki.eclipse.org/Eclipse.ini


    On a Mac OS X system, you can find eclipse.ini by right-clicking (or Ctrl+click) on the Eclipse executable in Finder, choose Show Package Contents, and then locate eclipse.ini in the MacOS folder under Contents.

  • kamil

    Dárcio Nuno, thank you so much!!!! You saved my life! And you did it on my birthday.

  • http://y/ reclaim your money

    “y/ Thanks for that awesome posting. It saved MUCH time :-)

  • Your bee

    Thanx for that awesome posting

    mac memory upgrade

canl sohbet hatt telefonda sex telefonda seks sex erotik sohbet hatt sex sex sex siki porno porno porno porno izle