1

SO i have written the following main function in java to compute editdistancee of 1000 random generated pairs of length 10, 20, 50 and 100. It is running fine for the lengths 10 n 20 but for length 50 it is giving this error. "Exception in thread "main" java.lang.OutOfMemoryError: Java heap space". I am confused what to do. any help would be appreciated.

for (j=0; j< numoftimes; j++) {
            for (int i = 0; i < len2; i++) {
                s5r += (char) ( 'a' + r.nextInt(26));
                s6r += (char) ( 'a' + r.nextInt(26));
            }
            starttime2 = System.nanoTime();
            int distance2 = editDistance(s5r,s6r); 
            endtime2 = System.nanoTime() - starttime2; 
            }

            avg_CPUtime2 = (endtime2/numoftimes);
            System.out.println("Average CPU time in nanoseconds for 1000 
               pair of random words of length "+len2+" : "+avg_CPUtime2);


            int len3 = 100;
            long starttime3 = 0;
            long endtime3 = 0;
            long avg_CPUtime3 = 0;
            String s7r = "";
            String s8r = "";
            for (j=0; j< numoftimes; j++) {
            for (int i = 0; i < len3; i++) {
                s7r += (char) ( 'a' + r.nextInt(26));
                s8r += (char) ( 'a' + r.nextInt(26));
            }
            starttime3 = System.nanoTime();
            int distance3 = editDistance(s7r,s8r); 
            endtime3 = System.nanoTime() - starttime3; 
            }

            avg_CPUtime3 = (endtime3/numoftimes);
            System.out.println("Average CPU time in nanoseconds for 1000 
              pair of random words of length "+len3+" : "+avg_CPUtime3);

the out is this

Average CPU time in nanoseconds for 1000 pair of random words of length 10 : 
 674163
  Average CPU time in nanoseconds for 1000 pair of random words of length 20 
     : 3128792
   Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
 at algorithmDesign.Sequences.editDistance(Sequences.java:12)
 at algorithmDesign.Sequences.main(Sequences.java:116)
1
  • My guess is that editDistance is poorly implemented, but without seeing the code behind that method, it's hard to know how to help you. Commented Oct 28, 2017 at 6:10

1 Answer 1

0

You have to increase the java heap space

In Run->Run Configuration find the Name of the class you have been running, select it, click the Arguments tab then add:

-Xms512M -Xmx1024M

to the VM Arguments section

Sign up to request clarification or add additional context in comments.

5 Comments

There's a duplicate already
I've incresed to -Xmx4000m. i don't know if this is right or wrong. but it is still not working. P.S: I'm new to java and eclipse
It will make your computer speed slow. This is a memory space we are talking about please read about it before.
sure. I'm going to read. thankx btw
You welcome make sure to except the answer if it worked for you

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.