0

I try to manipulate big strings in rascal and get constantly the following error:

java.lang.OutOfMemoryError: Java heap space(internal error).

I changed the following parameters in the eclipse.ini file:

-XX:MaxPermSize=1024m
-Xms256m 
-Xmx1024m

But that changes nothing.

The code looks like this:

public str removeBB(str file){
while(contains(file, "aB")){
    index1 = findFirst(file, "aB");
    index2 = (findFirst(file, "Ba") + 2);

    subString1 = substring(file, 0, index1);
    subString2 = substring(file, index2);

    file = subString1 + subString2;
}

return file;
}

How can i prevent this error? Are there ways to write that code so that it is more memory efficient?

valiano
  • 16,433
  • 7
  • 64
  • 79
  • Hey, you didn't change the occurrence of `BB`, which makes the while loop infinitely looping. – Raptor Oct 02 '13 at 12:06

1 Answers1

1

I don't see immediately why this code is thrashing memory, maybe because it finds index2 smaller than index1 in your example string?

But anyway, I would write something like using a regular expression and visit, instead of using indexOf:

visit (file) { case /aB.*Ba/ => "" }

Also, string slicing has a nicer syntax to use, instead of substring:

rascal>"asdlhfasldfhslf"[5..8] str: "fas"

Jurgen Vinju
  • 6,393
  • 1
  • 15
  • 26
  • perhaps this way you also loose the memory trashing behavior. Could you post an example string on which the memory goes sky high? – Jurgen Vinju Oct 05 '13 at 19:12