Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
内存不足错误:Java堆空间_Java_Out Of Memory_Mappedbytebuffer - Fatal编程技术网

内存不足错误:Java堆空间

内存不足错误:Java堆空间,java,out-of-memory,mappedbytebuffer,Java,Out Of Memory,Mappedbytebuffer,我正在尝试使用映射字节缓冲区读取文件,并在buffer.position(position)行获得一个OutOfMemoryError:JavaHeapSpace。。我不明白代码里出了什么问题。。错误的原因可能是什么 private void readFile() { int lastPos = buffer.getInt(); int dirLen = buffer.getInt(); byte[] dirBytes = new byte[dirLen]; b

我正在尝试使用映射字节缓冲区读取文件,并在buffer.position(position)行获得一个OutOfMemoryError:JavaHeapSpace。。我不明白代码里出了什么问题。。错误的原因可能是什么

private void readFile()
{
    int lastPos = buffer.getInt();

    int dirLen = buffer.getInt();
    byte[] dirBytes = new byte[dirLen];
    buffer.get(dirBytes);
    this.dir = new String(dirBytes);

    int filePatternLen = buffer.getInt();
    byte[] filePatternBytes = new byte[filePatternLen];
    buffer.get(filePatternBytes);
    this.filePattern = new String(filePatternBytes);

    int numFileMetaDatas = 0;
    while (buffer.position() < lastPos)
    {
        numFileMetaDatas++;
        int position = buffer.position();
        //Size is needed as we are reserving some extra bytes
        int size = buffer.getInt();
        buffer.position(position + ByteUtil.SIZE_OF_INT + ByteUtil.SIZE_OF_BYTE + ByteUtil.SIZE_OF_LONG + ByteUtil.SIZE_OF_LONG + ByteUtil.SIZE_OF_LONG);
        int fileNameLen = buffer.getInt();
        byte[] fileNameBytes = new byte[fileNameLen];
        buffer.get(fileNameBytes);

        FileMetaData fileMetaData = new FileMetaData(buffer, size, position);
        UniqueID uniqID = fileMetaData.getUniqueID();

        uniqIdVsFileMetaData.put(uniqID, fileMetaData);

        position = position + size;
        buffer.position(position);
    }
    nextMetaStartPos = lastPos;
}
private void readFile()
{
int lastPos=buffer.getInt();
int dirLen=buffer.getInt();
字节[]dirBytes=新字节[dirLen];
get(dirBytes);
this.dir=新字符串(dirBytes);
int filePatternLen=buffer.getInt();
字节[]filePatternBytes=新字节[filePatternLen];
get(filePatternBytes);
this.filePattern=新字符串(filePatternBytes);
int numFileMetaDatas=0;
while(buffer.position()
转到eclipse配置文件,即ini文件更改perm大小
下面的注释告诉您增加了permsize

-vm
C:/Program Files (x86)/Java/jdk1.6.0/bin/javaw.exe
-startup
plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.100.v20110502
-product
com.springsource.sts.ide
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
384M//incease to 512 mb
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xmn128m
-Xms256m
-Xmx768m
-Xss1m
-XX:PermSize=128m// increase to 512 mb 
-XX:MaxPermSize=384m//increase to 512 mb

解决java中OutOfMemoryError的简单方法是使用JVM选项“-Xmx512M”增加最大堆大小,这将立即解决OutOfMemoryError。当我在构建项目时遇到Eclipse、Maven或ANT中的内存错误时,这是我首选的解决方案,因为根据项目的大小,很容易耗尽内存,如果您在java应用程序中设置堆大小,那么最好将-Xmx与-Xms的比率保持为1:1或1:1.5

导出JVM_ARGS=“-Xms1024m-Xmx1024m”

2) 在Java中解决OutOfMemoryError的第二种方法是相当困难的,当您没有太多内存时,即使在增加最大堆大小之后,您仍然会得到Java.lang.OutOfMemoryError,在这种情况下,您可能希望评测应用程序并查找内存泄漏。您可以使用Eclipse内存分析器检查堆转储,也可以使用任何探查器,如Netbeans或JProbe。这是一个艰难的解决方案,需要一些时间来分析和发现内存泄漏

    -vm
C:/Program Files (x86)/Java/jdk1.6.0/bin/javaw.exe
-startup
plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.100.v20110502
-product
com.springsource.sts.ide
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
384M//incease to 512 mb
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xmn128m
-Xms256m
-Xmx768m
-Xss1m
-XX:PermSize=128m// increase to 512 mb 
-XX:MaxPermSize=384m//increase to 512 mb

转到eclipse配置文件,即ini文件更改永久大小,因为代码不包含所有信息。这里只是一个猜测
int size=buffer.getInt()可能返回一个巨大的整数。您是否看到此链接<>此链接将有所帮助。我认为只要增加堆大小就可以了。@Rishikesh。。增加堆大小不是解决方案,因为代码已经运行了好几个月了。但最近我发现了这个错误。你认为为什么会涉及到永久性激素?OP特别指出错误是在JavaHeapSpace中内存不足,而不是在PermGen空间中。@Erwin Bolwidt javaHeap空间和PermGen空间都显示在JVM内存不足时发生。当PermGen空间不足时,例外情况是
java.lang.OutOfMemoryError:PermGen空间
。OP说他的错误是
OutOfMemoryError:JavaHeapSpace
,因此没有迹象表明PermGen参与了这个问题。如果您仍然认为可能,您可以在评论中询问OP。@Erwin为什么否决投票回答两个错误略有不同,但我给出的解决方案可能会解决问题我不会同时否决投票和评论。但我理解投反对票的意思:答案不是为了直觉,特别是当它们与OP发布的内容相矛盾时。