ChatGPT解决这个技术问题 Extra ChatGPT

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.

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

V
Vinze

-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


Using Process Explorer (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.
what does x in xms stand for?
oracle.com/technetwork/java/javase/tech/… "Options that begin with -X are non-standard (not guaranteed to be supported on all VM implementations), and are subject to change without notice in subsequent releases of the JDK."
J
Jeremy Stein

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

This could be:

Eclipse itself (which I doubt) 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.


A
Andreas Mattisson

Found 2 issues in our case.

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 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.


c
chro

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


A
Adrian Pirvulescu

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.


K
Karl

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.


J
Jainendra

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.


J
Jainendra

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.


A
Aaron Digulla

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.


佚名

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.


D
DD_

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

关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now