Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.util.Arrays.copyOf(Unknown Source)
at java.util.ArrayList.grow(Unknown Source)
at java.util.ArrayList.ensureExplicitCapacity(Unknown Source)
at java.util.ArrayList.ensureCapacityInternal(Unknown Source)
at java.util.ArrayList.add(Unknown Source)
at FibonacciHeap.removemax(FibonacciHeap.java:148)
at UseFibonacciHeap.main(UseFibonacciHeap.java:61)
My java program on Eclipse is reading strings from a file and inserting them to an array list and doing a lot of computations ahead.It throws the above exceptions on encountering 150+ strings.I tried increasing the VM space,using sleep but Nothing works ! The eventual goal is to operate on 1 million strings(not all unique).
Edits:
Usage of the ArrayList toVisit:
for (FibonacciNode curr = max_ptr; toVisit.isEmpty() || toVisit.get(0) != curr; curr = curr.right_sibling)
{
toVisit.add(curr);
...
}
VM Arguments for the class: -Xms1024M -Xmx1524M
Can someone guide me to an optimal way of doing this.Is there a different data structure that I can use? Thanks !!
forloop is looping forever. Check the 'while' part of the loop (toVisit.isEmpty() || toVisit.get(0) != curr) - does this ever becomefalse?