[java] Eclipse memory settings when getting "Java Heap Space" and "Out of Memory"

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.

This question is related to java apache-flex eclipse memory

The answer is


-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

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.


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


Adobe Flash Builder 4.6 Read Me.pdf recommendeds that you edit the eclipse.ini file for your Eclipse instance, so that it includes the following settings:

-vmargs -Xms256m -Xmx512m -XX:MaxPermSize=256m -XX:PermSize=64m

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.


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.


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.


My FLashBuilder is crashing all the time when I try to release a new version or I abuse of the "Mark Occurrences" and "Link with editor" features.

I have improved significantly my flash performance by following this steps http://www.redcodelabs.com/2012/03/eclipse-speed-up-flashbuilder/

Especially by setting the FlashBuilder.ini to the following configuration

-vm
C:/jdk1.6.0_25/bin
-startup
plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
–launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.100.v20110502
-product
org.eclipse.epp.package.jee.product
–launcher.defaultAction
openFile
–launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
–launcher.XXMaxPermSize
256m
–launcher.defaultAction
openFile
-vmargs
-server
-Dosgi.requiredJavaVersion=1.5
-Xmn128m
-Xms1024m
-Xmx1024m
-Xss2m
-XX:PermSize=128m
-XX:MaxPermSize=128m
-XX:+UseParallelGC

My hardware configuration is intel i3 cpu, 4gb DDR3, windows 7 64Bit.


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.


Adobe Flash Builder 4.6 Read Me.pdf recommendeds that you edit the eclipse.ini file for your Eclipse instance, so that it includes the following settings:

-vmargs -Xms256m -Xmx512m -XX:MaxPermSize=256m -XX:PermSize=64m

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.


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.


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.


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.


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.


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.


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.


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.


My FLashBuilder is crashing all the time when I try to release a new version or I abuse of the "Mark Occurrences" and "Link with editor" features.

I have improved significantly my flash performance by following this steps http://www.redcodelabs.com/2012/03/eclipse-speed-up-flashbuilder/

Especially by setting the FlashBuilder.ini to the following configuration

-vm
C:/jdk1.6.0_25/bin
-startup
plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
–launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.100.v20110502
-product
org.eclipse.epp.package.jee.product
–launcher.defaultAction
openFile
–launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
–launcher.XXMaxPermSize
256m
–launcher.defaultAction
openFile
-vmargs
-server
-Dosgi.requiredJavaVersion=1.5
-Xmn128m
-Xms1024m
-Xmx1024m
-Xss2m
-XX:PermSize=128m
-XX:MaxPermSize=128m
-XX:+UseParallelGC

My hardware configuration is intel i3 cpu, 4gb DDR3, windows 7 64Bit.


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.


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.


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.


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


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.


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.


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.


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.


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to apache-flex

Failed to load JavaHL Library How to pass "Null" (a real surname!) to a SOAP web service in ActionScript 3 How do I get a HttpServletRequest in my spring beans? What is the best way to get the minimum or maximum value from an Array of numbers? Eclipse memory settings when getting "Java Heap Space" and "Out of Memory"

Examples related to eclipse

How do I get the command-line for an Eclipse run configuration? My eclipse won't open, i download the bundle pack it keeps saying error log strange error in my Animation Drawable How to uninstall Eclipse? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Class has been compiled by a more recent version of the Java Environment Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError for LauncherFactory How to downgrade Java from 9 to 8 on a MACOS. Eclipse is not running with Java 9 "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. on deploying to tomcat

Examples related to memory

How does the "view" method work in PyTorch? How do I release memory used by a pandas dataframe? How to solve the memory error in Python Docker error : no space left on device Default Xmxsize in Java 8 (max heap size) How to set Apache Spark Executor memory What is the best way to add a value to an array in state How do I read a large csv file with pandas? How to clear variables in ipython? Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine