[英]Eclipse Exception with java.lang.OutOfMemoryError: Java heap space
Hi I am partially testing an application and It has a problem with heap space. 嗨,我正在部分测试一个应用程序,它的堆空间有问题。 Here is sample code
这是示例代码
public class Test {
Test()
{
byte[] b = new byte[744678306];
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Test t=new Test();
}
}
Error 错误
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
Here is eclipse ini configuration 这是eclipse ini配置
-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_1.1.200.v20130807-1835
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.6
-XX:MaxPermSize=256m
-Xms800m
-Xmx999m
Working env : ubuntu 12 on vBox. 工作环境:vBox上的ubuntu 12。
Thanks advance. 谢谢前进。
You are asking for space for about 750MB, but your program starts with a maximum allowed of 256, 您要求的空间约为750MB,但是您的程序开始时最大允许为256MB,
Just add -Xmx2048M (for 2048 MB, you can change that number) in the list of VM arguments in the corresponding run configuration. 只需在相应运行配置的VM参数列表中添加-Xmx2048M(对于2048 MB,您可以更改该数字)。
The Eclipse startup configuration which you have pasted has nothing to do with your problem. 您粘贴的Eclipse启动配置与您的问题无关。 Eclipse does not execute your code in its own JVM;
Eclipse不在自己的JVM中执行代码; it starts a separate JVM with the arguments you explicitly specify within Eclipse .
它使用您在Eclipse中显式指定的参数启动一个单独的JVM。
After you run the application once, a Run Configuration entry will be created for it. 一次运行该应用程序后,将为其创建一个“运行配置”条目。 Go to that entry (Run -> Configurations...) and, under VM arguments, specify more memory with
-Xmx
. 转到该条目(运行->配置...),然后在VM参数下使用
-Xmx
指定更多内存。 By default, Java 7 sets mx
to 1 GB or a quarter of the total RAM, whichever is less. 默认情况下,Java 7将
mx
设置为1 GB或总RAM的四分之一,以较小者为准。
For avoiding the out of memory error do the following steps. 为避免内存不足错误,请执行以下步骤。 Eclipse -> run -> run configuration -> arguments .
Eclipse- > 运行 -> 运行配置 -> 参数 。 Then in VM arguments type as below.
然后在VM参数中键入以下内容。
-XX:MaxHeapSize=1024m
You can specify your own memory size. 您可以指定自己的内存大小。
I think you don't have many parameter in eclipse.ini 我认为您在eclipse.ini中没有太多参数
This is the best configuration for Eclipse NEON and os Windows 10 with 4GB of Ram: 这是带有4GB Ram的Eclipse NEON和os Windows 10的最佳配置:
-startup
plugins/org.eclipse.equinox.launcher_1.3.201.v20161025-1711.jar
–launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.401.v20161122-1740
-product
org.eclipse.epp.package.jee.product
–launcher.defaultAction
openFile
–launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
–launcher.XXMaxPermSize
256m
–launcher.defaultAction
openFile
-vm
C:/Program Files/Java/jdk1.8.0_121/bin/javaw.exe
–launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.8
-Xms256m
-Xmx512m
-XX:PermSize=256m
-XX:MaxPermSize=512m
If you have 8GB of Ram modify -XX:PermSize=512m and -XX:MaxPermSize=1024m . 如果您有8GB的Ram,请修改-XX:PermSize = 512m和-XX:MaxPermSize = 1024m 。 For complete example see here .
有关完整的示例,请参见此处 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.