views:

55841

answers:

10

When trying to launch and run a flex/java project in eclipse I kept getting a "Out of Memory Exception" and "Java Heap Space" using Eclipse, Tomcat and a JRE.

While researching trying to adjust the memory settings I found three places to adjust these:

  • Eclipse.ini

  • The JRE Settings under Window > Preferences

  • Catalina.sh or Catalina.bat

What are the differences between setting -xms and -xmx in these different places and what does is mean?

Is there any way to verify these memory settings are being set accordingly?

What are the optimal -xms and -xmx settings for a computer with 2gb of RAM?

Any other memory tips?

Thanks.

+14  A: 

-xms is the start memory (at the VM start), -xmx is the maximum memory for the VM

  • eclipse.ini : the memory for the VM running eclipse
  • jre setting : the memory for java programs run from eclipse
  • catalina.sh : the memory for your tomcat server
Vinze
Using Process Explorer (http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx), I saw that Eclipse.exe was using a lot of memory in the build process. Changing Eclipse.ini resolved this problem.
Brandon
A: 

This might help, too: http://stackoverflow.com/questions/316265/tricks-to-speed-up-eclipse#316535

Aaron Digulla
I agree (with my own answer)! Except that I tend to agree with Bruno Conde that the problem may be in this case with Tomcat and Catalina settings, rather than pure eclipse.ini settings
VonC
+2  A: 

There's a couple of different memory settings for good reason.

The eclipse memory setting is because Eclipse is a large java program. if you are going to have a huge amount of files open in a couple of projects, then you're going to want to give Eclipse more ram. This is an issue only on "enterprise" systems normally personal projects wont use that many file handles or interfaces.

The JRE setting is how much ram to allow the java runtime when you run your project. This is probably the one you want when you are running some memory hogging application. I've run mathematical projects that needed a few gigs of ram and had to really tell the JRE it was okay, the JVM kept assuming my program was in some leaky runaway state, but I was doing it on purpose, and had to tell JVM specifically what it was allowed to use.

Then Catalina's memory setting is for the application server Tomcat. That server needs memory for each application and concurrent users. This blends with the JRE number because your project might be a web application and I'm not sure which one needs the memory.

Karl
+8  A: 

First of all, I suggest that you narrow the problem to which component throws the "Out of Memory Exception".

This could be:

  1. Eclipse itself (which I doubt)
  2. Your application under Tomcat

The JVM parameters -xms and -xmx represent the heap's "start memory" and the "maximum memory". Forget the "start memory". This is not going to help you now and you should only change this parameter if you're sure your app will consume this amount of memory rapidly.

In production, I think the only parameter that you can change is the -xmx under the Catalina.sh or Catalina.bat files. But if you are testing your webapp directly from Eclipse with a configured debug environment of Tomcat, you can simply go to your "Debug Configurations" > "Apache Tomcat" > "Arguments" > "VM arguments" and set the -xmx there.

As for the optimal -xmx for 2gb, this depends a lot of your environment and the number of requests your app might take. I would try values from 500mb up to 1gb. Check your OS virtual memory "zone" limit and the limit of the JVM itself.

bruno conde
A: 

If you see an out of memory, consider if that is plausible: Do you really need that much memory? If not (i.e. when you don't have huge objects and if you don't need to create millions of objects for some reason), chances are that you have a memory leak.

In Java, this means that you're keeping a reference to an object somewhere even though you don't need it anymore. Common causes for this is forgetting to call close() on resources (files, DB connections, statements and result sets, etc.).

If you suspect a memory leak, use a profiler to find which object occupies all the available memory.

Aaron Digulla
A: 

Also have some problems with the memory in Eclipse, but the way it is for us, is not when the actual run, it is when Eclipse is doing a refresh (manually or auto), or if trying to build it, eclipse crash and are shutdown.

In the logs there are some info: Heap def new generation total 36352K, used 11534K [0x10040000, 0x127b0000, 0x14f00000) eden space 32320K, 29% used [0x10040000, 0x10994c30, 0x11fd0000) from space 4032K, 49% used [0x123c0000, 0x125aed80, 0x127b0000) to space 4032K, 0% used [0x11fd0000, 0x11fd0000, 0x123c0000) tenured generation total 483968K, used 125994K [0x14f00000, 0x327a0000, 0x50040000) the space 483968K, 26% used [0x14f00000, 0x1ca0ab38, 0x1ca0ac00, 0x327a0000) compacting perm gen total 58112K, used 57928K [0x50040000, 0x53900000, 0x60040000) the space 58112K, 99% used [0x50040000, 0x538d2160, 0x538d2200, 0x53900000) No shared spaces configured.

Even if i adjust the eclipse.ini to use these values it doesn't seems to be applied. -showsplash org.eclipse.platform --launcher.XXMaxPermSize 1024M -framework plugins\org.eclipse.osgi_3.4.2.R34x_v20080826-1230.jar -vmargs -Dosgi.requiredJavaVersion=1.5 -XX:MaxPermSize=256m -Xms512m -Xmx1024m

Any that have seen this issue before? Will add that the project that are used is very large.

Andreas Mattisson
+2  A: 

Found 2 issues in our case.

  1. The Memory was halting and we where mandatory to set the startup perm size to higher value. I guess it was using memory faster then able to allocate it. In our case. -XX:PermSize=256m -XX:MaxPermSize=256m

  2. We are using Clearcase and the plugin from Rational Clearcase SCM (7.0.0.2) was used in Eclipse. The plugin was the case of why Eclipse crashed. And at the moment we do not know why, but could be good to know for others. Was forced to disable it.

Andreas Mattisson
A: 

We hit a heap space issue with Ant while trying to build a very large Flex project which could not be solved by increasing the memory allocated to Ant or by adding the fork=true param. It ended up being a bug in Flex 3.4.0 sdk. I finally figured this out after polling the devs for their sdk version and reverting to 3.3.0.

For the curious.

I tracked the bug down to an Interface file that had an additional accessor pair added "get/set maskTrackSkin". The heap space error hit if any additional functions were added to the interface and to make things worse the interface was not in the project that was getting the heap space error. Hope this helps someone.

PRangel
A: 

Tomcat in Eclipse does not use catalina.sh or bat. To setup memory for managed Tomcat use VM settings in server run configuration

chro
A: 

I have these settings: -vmargs ... -Duser.name=... -XX:PermSize=256m -XX:MaxPermSize=256m -Xmn128m -Xms256m -Xmx768m Eclipse randomly crashed before I set the PermSize equal to MaxPermSize.

David