File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Eligibility for Garbage Collection" Watch "Eligibility for Garbage Collection" New topic

Eligibility for Garbage Collection

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.
Ranch Hand

Joined: Jul 15, 2000
Posts: 37
This type of quest were discussed before as well pls refer the following url
I agree. Here's the link:
subject: Eligibility for Garbage Collection
It's not a secret anymore!