获取“Java 堆空间”和“内存不足”时的 Eclipse 内存设置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/334102/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse memory settings when getting "Java Heap Space" and "Out of Memory"
提问by Brandon
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 不断收到“内存不足异常”和“Java 堆空间”。
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
Eclipse文件
Window > Preferences 下的 JRE 设置
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.
谢谢。
采纳答案by Vinze
-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
- jre setting : the memory for java programs run from eclipse
- catalina.sh : the memory for your tomcat server
- eclipse.ini : 运行 eclipse 的 VM 的内存
- jre 设置:用于从 Eclipse 运行的 Java 程序的内存
- catalina.sh : tomcat 服务器的内存
回答by 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.
eclipse内存设置是因为Eclipse是一个很大的java程序。如果您要在几个项目中打开大量文件,那么您将需要为 Eclipse 提供更多内存。这是仅在“企业”系统上的问题,通常个人项目不会使用那么多文件句柄或接口。
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.
JRE 设置是运行项目时允许 java 运行时的内存大小。当您运行一些内存占用应用程序时,这可能是您想要的。我运行过需要一些内存的数学项目,并且不得不真正告诉 JRE 没问题,JVM 一直假设我的程序处于某种泄漏的失控状态,但我是故意这样做的,并且不得不告诉 JVM特别是它被允许使用的内容。
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.
那么Catalina 的内存设置是针对应用服务器Tomcat 的。该服务器需要为每个应用程序和并发用户提供内存。这与 JRE 编号混合,因为您的项目可能是一个 Web 应用程序,我不确定哪个需要内存。
回答by bruno conde
First of all, I suggest that you narrow the problem to which component throws the "Out of Memory Exception".
首先,我建议您将问题缩小到哪个组件抛出“内存不足异常”。
This could be:
这可能是:
- Eclipseitself (which I doubt)
- Your applicationunder Tomcat
- Eclipse本身(我怀疑)
- 你在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.
JVM的参数-xms
和-xmx
表示堆的“启动内存”和“最大内存”。忘记“开始记忆”。这现在对您没有帮助,只有在您确定您的应用程序会快速消耗此内存量时,才应该更改此参数。
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.
在生产中,我认为您可以更改的唯一参数是-xmx
Catalina.sh 或 Catalina.bat 文件下的参数。但是,如果您使用 Tomcat 的已配置调试环境直接从 Eclipse 测试您的 web 应用程序,则只需转到“调试配置”>“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. I would try values from 500mb up to 1gb. Check your OS virtual memory "zone" limit and the limit of the JVM itself.
至于-xmx
2gb的最佳值,这在很大程度上取决于您的环境和您的应用程序可能需要的请求数量。我会尝试从 500mb 到 1gb 的值。检查您的操作系统虚拟内存“区域”限制和 JVM 本身的限制。
回答by 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.).
在 Java 中,这意味着即使不再需要某个对象,您也会在某处保留对它的引用。造成这种情况的常见原因是忘记对资源(文件、数据库连接、语句和结果集等)调用 close()。
If you suspect a memory leak, use a profiler to find which object occupies all the available memory.
如果您怀疑内存泄漏,请使用分析器查找哪个对象占用了所有可用内存。
回答by Andreas Mattisson
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.
任何人以前见过这个问题?
将补充说使用的项目非常大。
回答by Andreas Mattisson
Found 2 issues in our case.
在我们的案例中发现了 2 个问题。
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.
内存正在停止,我们必须将启动永久大小设置为更高的值。我猜它使用内存的速度更快,然后才能分配它。在我们的情况下。-XX:PermSize=256m -XX:MaxPermSize=256m
我们正在使用 Clearcase,并且在 Eclipse 中使用了来自 Rational Clearcase SCM (7.0.0.2) 的插件。插件就是Eclipse崩溃的原因。目前我们不知道为什么,但对其他人来说可能是件好事。被迫禁用它。
回答by Andreas Mattisson
We hit a heap space issue with Ant while trying to build a very large Flex project which could notbe 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.
我们打了一个堆空间问题,使用Ant而试图建立一个非常大的Flex项目可能无法通过增加分配给蚂蚁内存或添加叉=真PARAM来解决。它最终成为 Flex 3.4.0 sdk 中的一个错误。在轮询开发人员的 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". 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.
我将错误追踪到一个接口文件,该文件有一个额外的访问器对添加了“get/set maskTrackSkin”。如果在接口中添加了任何附加功能,并且更糟的是接口不在出现堆空间错误的项目中,则会出现堆空间错误。希望这可以帮助某人。
回答by chro
Tomcat in Eclipse does not use catalina.sh or bat. To setup memory for managed Tomcat use VM settings in server run configuration
Eclipse 中的 Tomcat 不使用 catalina.sh 或 bat。要为托管 Tomcat 设置内存,请使用服务器运行配置中的 VM 设置
回答by dmatej
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 随机崩溃了。
回答by 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.
当我尝试发布新版本或滥用“标记出现次数”和“与编辑器链接”功能时,我的 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。