有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java中的Eclipse异常。lang.OutOfMemoryError:Java堆空间

您好,我正在部分测试一个应用程序,它的堆空间有问题。 下面是示例代码

public class Test {


Test()
{
    byte[] b = new byte[744678306];
}


public static void main(String[] args) {
    // TODO Auto-generated method stub
    Test t=new Test();
}

}

错误

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

下面是EclipseINI配置

-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

工作环境:vBox上的Ubuntu12

提前谢谢


共 (4) 个答案

  1. # 1 楼答案

    我认为eclipse中没有太多参数。伊尼

    这是Eclipse NEON和o.s.Windows 10的最佳配置,内存为4GB:

    -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
    

    如果您有8GB内存,请修改-XX:PermSize=512m-XX:MaxPermSize=1024m。 有关完整示例,请参见here

  2. # 2 楼答案

    您要求的空间约为750MB,但您的程序开始时允许的最大空间为256

    看看this

    只需在相应运行配置的VM参数列表中添加-Xmx2048M(对于2048MB,您可以更改该数字)

  3. # 3 楼答案

    您粘贴的Eclipse启动配置与您的问题无关。Eclipse不会在自己的JVM中执行代码;它使用您在Eclipse中显式指定的参数启动一个单独的JVM

    运行应用程序一次后,将为其创建一个运行配置条目。转到该条目(运行->;配置…)并且,在VM参数下,使用-Xmx指定更多内存。默认情况下,Java7将mx设置为1GB或总RAM的四分之一,以较小者为准

  4. # 4 楼答案

    为避免内存不足错误,请执行以下步骤Eclipse->跑步->运行配置参数。然后在VM参数中输入如下

    -XX:MaxHeapSize=1024m 
    

    您可以指定自己的内存大小