title: Garbage collection of String literals in Java 6 and Java 7(Oracle Jdk)
body: <p>According to the famous book <a href="http://uet.vnu.edu.vn/~chauttm/e-books/java/Head-First-Java-2nd-edition.pdf" rel="nofollow noreferrer">Head first Java Page 661</a>:<br/><br/> "<code>Garbage Collector doesn't go inside String pool.</code>"</p>
  
  <p>After reading about the similar questions on SO, i have found mixed answers like:</p>
  
  <ol>
  <li>Garbage collection of String literals is same as normal objects.
  <a href="https://stackoverflow.com/questions/18406703/when-will-a-string-be-garbage-collected-in-java">Read this</a></li>
  <li>Some answers say the opposite. <a href="https://stackoverflow.com/questions/15324143/garbage-collection-of-string-literals">Read answer here</a>.</li>
  </ol>
  
  <p><strong>My Questions are:</strong></p>
  
  <ol start="3">
  <li><p>How were the string literals garbage collected in Java 6 and before
  ?</p></li>
  <li><p>And since in Java 7 , <a href="http://www.oracle.com/technetwork/java/javase/jdk7-relnotes-418459.html#jdk7changes" rel="nofollow noreferrer">string literals will be created on heap</a>,
  how the garbage collection of string literals will be different
  in Java 7  as compared to the java 6?</p></li>
  </ol>