• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Eligibility for Garbage Collection

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
How many strings are eligible to be garbage collected after the execution of line 2 and line 4?
public class TestClass
{
public static void main(String args[ ] )
{
String str0 = null;
String str1 = "some string";
String str2 = "second string";
String str3 = "Third string";
str0 = str1; // 1
str1 = null; //2
str2 = str0; //3
str3 = str2; // 4
}
}
Could someone pls explain me this in detail... .I had a notion that once u assigna object reference to a different reference, the first reference doesnt exists no more. (str0 = "a"; str1 = "b"; str1 = str0) I thought (or rather I think) reference str0 is lost after this... someone pls help me.
 
jafarali
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This type of quest were discussed before as well pls refer the following url
http://www.javaranch.com/ubb/Forum24/HTML/000126.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic