java.lang.OutOfMemoryError:为100万个元素创建数据结构时超出了GC开销限制

java.lang.OutOfMemoryError:为100万个元素创建数据结构时超出了GC开销限制,java,garbage-collection,svm,libsvm,Java,Garbage Collection,Svm,Libsvm,当我运行下面显示的代码时,我得到一个java.lang.OutOfMemoryError:第16行超出了GC开销限制:svm\u node=new svm\u node;。该代码在约100万个元素的数组上运行,其中每个元素可容纳100个元素 // read in a problem (in svmlight format) private void read(SupportVector[] vectors) throws IOException { int length = vector

当我运行下面显示的代码时,我得到一个java.lang.OutOfMemoryError:第16行超出了GC开销限制:svm\u node=new svm\u node;。该代码在约100万个元素的数组上运行,其中每个元素可容纳100个元素

// read in a problem (in svmlight format)
private void read(SupportVector[] vectors) throws IOException
{
    int length = vectors.length; // Length of training data
    double[] classification = new double[length]; // This is redundant for our one-class SVM.
    svm_node[][] trainingSet = new svm_node[length][]; // The training set.
    for(int i = 0; i < length; i++)
    {
        classification[i] = 1; // Since classifications are redundant in our setup, they all belong to the same class, 1.

        // each vector. The vector has to be one index longer than the actual vector,
        // because the implementation needs an empty node in the end with index -1.
        svm_node[] vector = new svm_node[vectors[i].getLength() + 1];

        double[] doubles = vectors[i].toDouble(); // The SVM runs on doubles.
        for(int j = 0; j < doubles.length; j++) {
            svm_node node = new svm_node();
            node.index = j;
            node.value = doubles[j];
            vector[j] = node;
        }
        svm_node last = new svm_node();
        last.index = -1;
        vector[vector.length - 1] = last;

        trainingSet[i] = vector;
    }

    svm_problem problem = new svm_problem();
    problem.l = length;
    problem.y = classification;
    problem.x = trainingSet;
}
从例外情况来看,我猜垃圾收集器无法正确地清理我的新svm_节点,但我无法看到如何优化对象创建,以避免创建太多无助于堆中的新svn_节点

我不能改变数据结构,因为它是支持向量机的输入

我的问题是:这个错误与垃圾收集器无法收集我的svm_节点有关,还是我只是试图解析包含太多元素的数据结构


PS:我已经将32位应用程序2gb的堆大小设置为最大值。

我在64位环境中启动了该应用程序,并将堆大小提高到2gb以上,从而解决了问题。我仍然认为存在一个奇怪的GC怪癖,但我无法找到它,增加堆也解决了这个问题。

为什么不为应用程序使用64位地址空间?我认为拥有更多内存会有所帮助。现在很多手机都有2GB。你可以花200美元买16GB。我不确定这是否是问题所在。错误表明GC使用了太多的CPU,但您认为这是与堆空间相关的问题吗?如果请求的数组大小是问题所在,您将得到:java.lang.OutOfMemoryError:请求的数组大小超过VM限制请查看此链接: