I have looked through all the memory leak solutions for java substring method. I still get the out of memory error due to this issue. I have an arraylist of string which are of length 1000-3500. i index them and store them. The issue is each string needs to be run through loop to store all possible varying lengths of same string. To do this, i use for loop and substring method. and this method causes the memory leak problem.
A sudo code of what i have done:
for(int i=0;i<str.length;i++)
{
//create substring and index it
str.substring(0,(str.length()-i));
}
str: string. and this above loops runs till all the string within the arraylist are indexed. I tried to fix the leak by,
1.
for(int i=0;i<str.length;i++)
{
//create substring and index it
new String(str.substring(0,(str.length()-i)));
}
2.
for(int i=0;i<str.length;i++)
{
//create substring and index it
new String(str.substring(0,(str.length()-i)).intern());
}
3.
for(int i=0;i<str.length;i++)
{
//create substring and index it
new String(str.substring(0,(str.length()-i))).intern();
}
Still i have the issue. My java version is: 1.7.0_17.
Edit:
I understand this is not a memory leak problem from the comments. I am indexing some continuous strings. Say for example,
String s= abcdefghijkl;
i want index each string as :
abcdefghjk
abcdefghj
abcdefhg
abcdefh
abcdef
abcde
abcd
..
..
a
To perform this,i get a string,then perform substring operation,get that string and index them.