0

my code is for some reason giving me an out of memory error. I have tried increasing the amount of memory allocated to ecplise but it seems to do nothing. This is my code that the error is coming from:

public static ArrayList<Integer> getSortedEndPoints(ArrayList<Interval>leftSortedIntervals, ArrayList<Interval> rightSortedIntervals) {
    int left;
    int size = leftSortedIntervals.size();
    Interval interval;
    ArrayList <Integer> sortedEndPoints = new ArrayList<Integer>();
    for (int i = 0; i < size; i++){
        interval = leftSortedIntervals.get(i);
        left = interval.leftEndPoint;
        //System.out.println("Left Endpoint at " + i + "is : " + left);
        if (sortedEndPoints.size() == 0){
            //System.out.println("Entered size 0");
            sortedEndPoints.add(left);
        } else if (searchForDuplicate(sortedEndPoints, left) == false){
            //System.out.println("Search For Duplicates is False");
            sortedEndPoints.add(left);
        }
    }
    System.out.println("Sorted End Points after left search : " + sortedEndPoints);

    int right;
    size = rightSortedIntervals.size();
    for (int i = 0; i < size; i++){
        interval = rightSortedIntervals.get(i);
        right = interval.rightEndPoint;
        if (sortedEndPoints.size() == 0){
            sortedEndPoints.add(right);
        } else if (searchForDuplicate(sortedEndPoints, right) == false){
            System.out.println("Search For Duplicates is False");
            size = sortedEndPoints.size()-1;
            System.out.println("Size= " + size);
            System.out.println("sortedEndPoints.get(size) " + sortedEndPoints.get(size));
            if (right > sortedEndPoints.get(size)){
                sortedEndPoints.add(right);
            } else {
            for (int t = 0; t < sortedEndPoints.size(); t++){
                if (right < sortedEndPoints.get(t)){
                    sortedEndPoints.add(t, right);
                    }
                }
            }
        }
    }
    System.out.println("Sorted End Points after right search : " + sortedEndPoints);
    return sortedEndPoints;
}


private static boolean searchForDuplicate(ArrayList<Integer>sortedEndPoints, int left){
    for (int track = 0; track < sortedEndPoints.size(); track++){
        if (left == sortedEndPoints.get(track)){
            return true;
        }
    }
    return false;
}

and this is the error I am getting

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Arrays.java:2760)
    at java.util.Arrays.copyOf(Arrays.java:2734)
    at java.util.ArrayList.ensureCapacity(ArrayList.java:167)
    at java.util.ArrayList.add(ArrayList.java:370)
    at structures.Sorter.getSortedEndPoints(Sorter.java:148)
    at structures.IntervalTree.<init>(IntervalTree.java:39)
    at apps.IntervalTreeDriver.main(IntervalTreeDriver.java:19)

I have no idea what to do now...

trincot
  • 317,000
  • 35
  • 244
  • 286

1 Answers1

0

Values in the eclipse.ini change the memory that Eclipse uses itself, not what it uses when you run a program.

To change what your program uses when you run it open the 'Run > Run Configurations' dialog. Find your program in the 'Java Programs' section. On the 'Arguments' tab add your memory arguments in the 'VM arguments' section.

greg-449
  • 109,219
  • 232
  • 102
  • 145