Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 940
Brandon Avatar asked Dec 02 '08 14:12

Brandon


People also ask

How do I fix Java out of memory error heap space?

OutOfMemoryError: Java heap space. 1) An easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options "-Xmx512M", this will immediately solve your OutOfMemoryError.

How do I fix heap memory in Eclipse?

Temporary fix – Increase the heap size On the Eclipse menu, clicks Run -> Run Configurations.. , select the Java application we want to run, click on the Arguments tab, VM arguments section, and adjust a better Java initial maximum heap size.

How do I resolve out of memory exception in eclipse?

Increase Permgen Space in Eclipse If you are using below Java 8, then you might get OutOfMemoryError: Permgen space, just increase the permanent generation space available to Eclipse.


2 Answers

-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
like image 67
Vinze Avatar answered Sep 27 '22 18:09

Vinze


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.

like image 30
bruno conde Avatar answered Sep 27 '22 17:09

bruno conde