memory management in java strings?
<p>I have created strings object as given below</p>

<p>Case 1:</p>

<pre><code>  String s1="mystring";//Address location is 1000
  String s1="yourstring";
  String s2="mystring";
</code></pre>

<p>Case 2:</p>

<pre><code>  String s1=new String("mystring");//Address location is 1000
  String s1=new String("yourstring");
  String s2=new String("mystring");
</code></pre>

<p>with <a href="http://www.javaclass.info/classes/java-lang-string/java-string/java-string-examples-code-how-to.php" rel="nofollow">ref</a>.</p>

<p>As per my knowledge these string are stored in string constant pool for Case1 with specific memory locations, similarly in case2 objects are created in Heap memory. How does these memory will be managed and freed by garbage collector if we assign same or different strings to String objects.       </p>
