Get your CodeRanch badge!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Eligibility for Garbage Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Eligibility for Garbage Collection" Watch "Eligibility for Garbage Collection" New topic
Author

Eligibility for Garbage Collection

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Jul 15, 2000
Posts: 37
This type of quest were discussed before as well pls refer the following url
http://www.javaranch.com/ubb/Forum24/HTML/000126.html
 
 
subject: Eligibility for Garbage Collection
 
Similar Threads
Fussed up with GC
Garbage Collection and String Literals
JQ+ #954287145350
Regarding Data Insertion
equals() and ==, doubt