J
Jaap de Bergen
Hello,
I'm writing a parser which uses Pattern and Matcher from
java.util.regex.*. After about 300 parses i receive a outofmemory
error.
After running a optimizer i discover that the resulting string of a
regular expression is 56KB big. The strange thing is the length of the
string is only 15 or 16 chars.
The code i'm using:
=======
m = Pattern.compile(REGEX, Pattern.MULTILINE |
Pattern.CASE_INSENSITIVE).matcher(INPUT);
while (m.find()) {
temp = m.group(1);
wm.add(temp);
}
======
The temp variable is 56KB big but only 15 chars long.
I'm now using:
======
temp = new String(m.group(1));
======
Which seems to work, no more outofmemory errors
And temp is only a
couple of bytes big. Could someone explain why the size of the temp
variable is much smaller? Has is something todo with references to
objects which Pattern/Matcher uses internal?
Thanks!
Jaap
I'm writing a parser which uses Pattern and Matcher from
java.util.regex.*. After about 300 parses i receive a outofmemory
error.
After running a optimizer i discover that the resulting string of a
regular expression is 56KB big. The strange thing is the length of the
string is only 15 or 16 chars.
The code i'm using:
=======
m = Pattern.compile(REGEX, Pattern.MULTILINE |
Pattern.CASE_INSENSITIVE).matcher(INPUT);
while (m.find()) {
temp = m.group(1);
wm.add(temp);
}
======
The temp variable is 56KB big but only 15 chars long.
I'm now using:
======
temp = new String(m.group(1));
======
Which seems to work, no more outofmemory errors
couple of bytes big. Could someone explain why the size of the temp
variable is much smaller? Has is something todo with references to
objects which Pattern/Matcher uses internal?
Thanks!
Jaap