title: How unreferred values from string pool get removed?
body: <p>I'm curious how values from a string-pool get removed? </p>
  
  <p>suppose: </p>
  
  <pre><code>String a = "ABC"; // has a reference of string-pool
  String b = new String("ABC"); // has a heap reference
  
  b = null;
  a = null;
  </code></pre>
  
  <p>In case of GC, "ABC" from the heap gets collected but "ABC" is still in the pool (because its in permGen and GC would not affect it). </p>
  
  <p>If we keep adding values like: </p>
  
  <pre><code>String c = "ABC"; // pointing to 'ABC' in the pool. 
  
  for(int i=0; i&lt; 10000; i++) {
    c = ""+i;
    // each iteration adds a new value in the pool. Previous values don't have a pointer.
  }
  </code></pre>
  
  <p>What I want to know is: </p>
  
  <ul>
  <li>Will the pool remove values that are not referred to? If not, it means that the pool is eating up unnecessary memory. </li>
  <li>What is the point then because the JVM is using the pool? </li>
  <li>When could this be a performance risk?</li>
  </ul>