title: memory leak issue on using java substring method
body: <p>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.</p>
  
  <p>A sudo code of what i have done:</p>
  
  <pre><code>for(int i=0;i&lt;str.length;i++)
  {
      //create substring and index it
      str.substring(0,(str.length()-i));
  }
  </code></pre>
  
  <p>str: string. and this above loops runs till all the string within the arraylist are indexed. I tried to fix the leak by,</p>
  
  <p>1.</p>
  
  <pre><code>for(int i=0;i&lt;str.length;i++)
  {
      //create substring and index it
      new String(str.substring(0,(str.length()-i)));
  }
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>for(int i=0;i&lt;str.length;i++)
  {
      //create substring and index it
      new String(str.substring(0,(str.length()-i)).intern());
  }
  </code></pre>
  
  <p>3.</p>
  
  <pre><code>for(int i=0;i&lt;str.length;i++)
  {
      //create substring and index it
      new String(str.substring(0,(str.length()-i))).intern();
  }
  </code></pre>
  
  <p>Still i have the issue. My java version is: 1.7.0_17.</p>
  
  <p>Edit:</p>
  
  <p>I understand this is not a memory leak problem from the comments. I am indexing some continuous strings. Say for example, </p>
  
  <pre><code>String s= abcdefghijkl;
  </code></pre>
  
  <p>i want index each string as :</p>
  
  <pre><code>abcdefghjk
  abcdefghj
  abcdefhg
  abcdefh
  abcdef
  abcde
  abcd
  ..
  ..
  a
  </code></pre>
  
  <p>To perform this,i get a string,then perform substring operation,get that string and index them.</p>