Exception java.lang.OutOfMemoryError:Java堆空间在递归中发生

问题描述 投票:0回答:1

我正在使用IntelliJ作为编辑器。这些是我的vmoptions:

-Xms1024m

-Xmx4096m

-XX:MaxPermSize=700m

-XX:ReservedCodeCacheSize=480m

-XX:SoftRefLRUPolicyMSPerMB=50

还有其他设置可以更改以使其对我有用吗?

我的算法试图通过Branch&Bound计算矩阵链乘法问题,在这一部分(下面的代码)中,我正在执行深度搜索/创建后继程序等。我认为此递归会触发堆问题。

 public  static  SimpleMCPNode createTree(SimpleMCPNode currentNode) {
//other statements 
.
.
.
.
for (int i = 0; i < currentNode.matrices.size() - 1; i++) {
        List<MatrixInfo> adaptedList = new ArrayList(currentNode.matrices);
        currentNode.successors.add(createTree(currentNode.createSuccessor(adaptedList, i)));
    }
//other statements
.
.

取决于输入,它可以成倍增长...

java recursion heap heap-memory
1个回答
0
投票
请使用:

ArrayList<Integer> adaptedList = new ArrayList<Integer>(); for(int i=0; i< 10; i++){ currentNode.successors.add(createTree(currentNode.createSuccessor(adaptedList,i))); adaptedList.clear() }

© www.soinside.com 2019 - 2024. All rights reserved.