[英]heap and stack in eclipse
I have written a code in Eclipse which runs properly for small input values but as soon as my test cases increase in size, i get OutOfMemoryException
or StackOverFlow
error. 我已经在Eclipse中编写了一个代码,该代码可以针对较小的输入值正常运行,但是一旦我的测试用例增加了大小,就会出现
OutOfMemoryException
或StackOverFlow
错误。
i tried to use eclipse.exe -vmargs -Xmx1g
to make my heap go out to 1G but i still get the same error. 我试图使用
eclipse.exe -vmargs -Xmx1g
使我的堆溢出到1G,但是我仍然遇到相同的错误。 and When i try 2G it says unable to start JVM. 当我尝试2G时,它说无法启动JVM。
so im wondering if there is any ways at all for me to run this code. 所以我想知道我是否有任何方式可以运行此代码。 any help would be appreciated.
任何帮助,将不胜感激。 thanks in advance.
提前致谢。
EDIT: this is where my heaps overflows. 编辑:这是我的堆溢出的地方。 the input sample is too huge and causes the momory problem.
输入样本太大,会导致记忆问题。
while ((line = br.readLine()) != null) {
String[] linevalue= (line.trim().split("\\s+"));
int l= linevalue.length;
dg.addNode(Long.parseLong(linevalue[0]));
dg.addNode(Long.parseLong(linevalue[1]));
dg.addEdge(Long.parseLong(linevalue[0]), Long.parseLong(linevalue[1]));
}
In the other class the following code is present, here mGraph is a HashMap. 在另一个类中,存在以下代码,其中mGraph是HashMap。
public boolean addNode(T node) {
/* If the node already exists, don't do anything. */
if (mGraph.containsKey(node))
return false;
/* Otherwise, add the node with an empty set of outgoing edges. */
mGraph.put(node, new HashSet<T>());
return true;
}
public void addEdge(T start, T dest) {
/* Confirm both endpoints exist. */
if (!mGraph.containsKey(start) || !mGraph.containsKey(dest))
throw new NoSuchElementException("Both nodes must be in the graph.");
/* Add the edge. */
mGraph.get(start).add(dest);
}
In Eclipse, you can set the size of the VM when you execute your code. 在Eclipse中,您可以在执行代码时设置VM的大小。
Go to Run > Run configurations
. 转到
Run > Run configurations
。 Then in the tab Arguments
, put -Xms1000m
under VM arguments. 然后在
Arguments
标签中,将-Xms1000m
放在VM参数下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.