简体   繁体   English

获取“Java堆空间”和“内存不足”时的Eclipse内存设置

[英]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. 当尝试在eclipse中启动并运行flex / java项目时,我使用Eclipse,Tomcat和JRE继续获得“Out of Memory Exception”和“Java Heap Space”。

While researching trying to adjust the memory settings I found three places to adjust these: 在研究尝试调整内存设置时,我找到了三个地方来调整这些:

  • Eclipse.ini 的eclipse.ini

  • The JRE Settings under Window > Preferences 窗口>首选项下的JRE设置

  • Catalina.sh or Catalina.bat Catalina.sh或Catalina.bat

What are the differences between setting -xms and -xmx in these different places and what does is mean? 在这些不同的地方设置-xms和-xmx之间有什么区别?这意味着什么?

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? 具有2GB RAM的计算机的最佳-xms和-xmx设置是什么?

Any other memory tips? 还有其他记忆提示吗?

Thanks. 谢谢。

-xms is the start memory (at the VM start), -xmx is the maximum memory for the VM -xms是启动内存(在VM启动时), - xmx是VM的最大内存

  • eclipse.ini : the memory for the VM running eclipse eclipse.ini:运行eclipse的VM的内存
  • jre setting : the memory for java programs run from eclipse jre设置:java程序的内存从eclipse运行
  • catalina.sh : the memory for your tomcat server catalina.sh:tomcat服务器的内存

First of all, I suggest that you narrow the problem to which component throws the "Out of Memory Exception". 首先,我建议您将问题缩小到哪个组件抛出“Out of Memory Exception”。

This could be: 这可能是:

  1. Eclipse itself (which I doubt) Eclipse本身(我怀疑)
  2. Your application under Tomcat Tomcat下的应用程序

The JVM parameters -xms and -xmx represent the heap's "start memory" and the "maximum memory". JVM参数-xms-xmx表示堆的“起始内存”和“最大内存”。 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. 在生产中,我认为您可以更改的唯一参数是Catalina.sh或Catalina.bat文件下的-xmx 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. 但是如果您使用配置的Tomcat调试环境直接从Eclipse测试您的webapp,您只需转到“调试配置”>“Apache Tomcat”>“参数”>“VM参数”并在那里设置-xmx

As for the optimal -xmx for 2gb, this depends a lot of your environment and the number of requests your app might take. 至于-xmx的最佳-xmx ,这取决于您的环境和应用程序可能需要的请求数量。 I would try values from 500mb up to 1gb. 我会尝试从500mb到1gb的值。 Check your OS virtual memory "zone" limit and the limit of the JVM itself. 检查操作系统虚拟内存“区域”限制和JVM本身的限制。

Found 2 issues in our case. 在我们的案例中发现了2个问题

  1. The Memory was halting and we where mandatory to set the startup perm size to higher value. 内存正在暂停,我们必须将启动perm大小设置为更高的值。 I guess it was using memory faster then able to allocate it. 我想它更快地使用内存然后能够分配它。 In our case. 在我们的例子中。 -XX:PermSize=256m -XX:MaxPermSize=256m -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. 我们正在使用Clearcase,并且Eclipse中使用了Rational Clearcase SCM(7.0.0.2)中的插件。 The plugin was the case of why Eclipse crashed. 这个插件就是为什么Eclipse崩溃了。 And at the moment we do not know why, but could be good to know for others. 目前我们不知道为什么,但对其他人来说可能会很好。 Was forced to disable it. 被迫禁用它。

Tomcat in Eclipse does not use catalina.sh or bat. Eclipse中的Tomcat不使用catalina.sh或bat。 To setup memory for managed Tomcat use VM settings in server run configuration 要为托管Tomcat设置内存,请在服务器运行配置中使用VM设置

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. 当我尝试发布新版本或滥用“Mark Occurrences”和“Link with editor”功能时,我的FLashBuilder一直崩溃。

I have improved significantly my flash performance by following this steps http://www.redcodelabs.com/2012/03/eclipse-speed-up-flashbuilder/ 按照以下步骤显着提高了我的闪存性能http://www.redcodelabs.com/2012/03/eclipse-speed-up-flashbuilder/

Especially by setting the FlashBuilder.ini to the following configuration 特别是通过将FlashBuilder.ini设置为以下配置

-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. 我的硬件配置是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. Eclipse中的内存也存在一些问题,但它对我们来说是不是在实际运行时,它是在Eclipse进行刷新(手动或自动)时,或者是在尝试构建它时,eclipse崩溃并且是关掉。

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. 即使我调整eclipse.ini使用这些值,它似乎也没有被应用。

-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. 将添加使用的项目非常大。

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. 在将PermSize设置为MaxPermSize之前,Eclipse随机崩溃。

There's a couple of different memory settings for good reason. 有充足的理由有几种不同的内存设置。

The eclipse memory setting is because Eclipse is a large java program. eclipse内存设置是因为Eclipse是一个大型的java程序。 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. 如果你打算在几个项目中打开大量的文件,那么你就会想要给Eclipse更多的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. JRE设置是在运行项目时允许java运行时的ram。 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. 我已经运行了需要几个ram的数学项目,并且必须真正告诉JRE它没关系,JVM一直认为我的程序处于漏斗失控状态,但我是故意这样做的,并且不得不告诉JVM具体是什么允许使用。

Then Catalina's memory setting is for the application server Tomcat. 然后Catalina的内存设置用于应用程序服务器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. 这与JRE编号混合在一起,因为您的项目可能是一个Web应用程序,我不确定哪个需要内存。

Adobe Flash Builder 4.6阅读Me.pdf建议您编辑Eclipse实例的eclipse.ini文件,以便它包含以下设置:

-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. 我们在尝试构建一个非常大的Flex项目时遇到了Ant的堆空间问题,这个项目无法通过增加分配给Ant的内存或添加fork = true param来解决。 It ended up being a bug in Flex 3.4.0 sdk. 它最终成为Flex 3.4.0 sdk中的一个错误。 I finally figured this out after polling the devs for their sdk version and reverting to 3.3.0. 在最初查看开发人员的sdk版本并恢复到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". 我将错误跟踪到一个接口文件,该文件有一个额外的存取器对添加了“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. 希望这有助于某人。

If you see an out of memory, consider if that is plausible: Do you really need that much memory? 如果你看到内存不足,请考虑是否合理:你真的需要那么多内存吗? If not (ie 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. 在Java中,这意味着即使您不再需要它,也可以在某个地方保留对某个对象的引用。 Common causes for this is forgetting to call close() on resources (files, DB connections, statements and result sets, etc.). 导致这种情况的常见原因是忘记在资源(文件,数据库连接,语句和结果集等)上调用close()。

If you suspect a memory leak, use a profiler to find which object occupies all the available memory. 如果您怀疑内存泄漏,请使用分析器查找哪个对象占用所有可用内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM