Anurag Ramdasan
Anurag Ramdasan

Reputation: 4340

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.

i tried to use eclipse.exe -vmargs -Xmx1g to make my heap go out to 1G but i still get the same error. and When i try 2G it says unable to start JVM.

so i m 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.

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);
}

Upvotes: 0

Views: 547

Answers (2)

Amir Afghani
Amir Afghani

Reputation: 38561

To follow up on tskuzzy's answer:

For heap,

-Xms -Xmx

For stack

-Xss

I would recommend 1g for Xmx and Xmx, and 8m for -Xss

Upvotes: 0

tskuzzy
tskuzzy

Reputation: 36476

In Eclipse, you can set the size of the VM when you execute your code.

Go to Run > Run configurations. Then in the tab Arguments, put -Xms1000m under VM arguments.

Upvotes: 1

Related Questions