I looked through all the memory leak solutions for the java substring method. Due to this problem, I still get an error from memory. I have an arraist from a string 1000-3500 long. I index them and store them. The problem is that each line must run through a loop to store all the possible variables of the length of the same line. For this, I use the loop and substring method. and this method causes a memory leak problem.
The sudo code of what I did:
for(int i=0;i<str.length;i++)
{
//create substring and index it
str.substring(0,(str.length()-i));
}
str: string. and these loops above are executed until the entire line inside the arraylist is indexed. I tried to fix the leak,
1.
for(int i=0;i<str.length;i++)
{
new String(str.substring(0,(str.length()-i)));
}
2.
for(int i=0;i<str.length;i++)
{
new String(str.substring(0,(str.length()-i)).intern());
}
3.
for(int i=0;i<str.length;i++)
{
new String(str.substring(0,(str.length()-i))).intern();
}
Still, I have a problem. My java version: 1.7.0_17.
Edit:
, . . , ,
String s= abcdefghijkl;
:
abcdefghjk
abcdefghj
abcdefhg
abcdefh
abcdef
abcde
abcd
..
..
a
, , , .