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 Garbage Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage Collection" Watch "Garbage Collection" New topic

Garbage Collection

Ankur Gupta
Ranch Hand

Joined: Jun 13, 2000
Posts: 66
Q29 from
29.At what stage in the following method does the string "abc" becomes available for garbage collection. Select the one correct answer.

A.Before statement labelled 1
B.Before statement labelled 2
C.Before statement labelled 3
D.Before statement labelled 4
The answer is D. Should it not be C ? i.e. Before stmt 3.
Ajith Kallambella

Joined: Mar 17, 2000
Posts: 5782
The same question has been discussed here


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Ankur Gupta
Ranch Hand

Joined: Jun 13, 2000
Posts: 66
Oops! Need to be more regular at the ranch, I guess!!
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
void method X()
String r = new String("abc");
String s = "abc";
r = r+1; //1
r = null; //2
s = s + r; //3
} //4
Hi ankur which String u r talking about is the String present in Heap memory that was created using statement String r = new String("abc");
Well if this is the string u r expecting it would be eligible for garabage collection at anytime after line marked with //1 is executed.
if u r talking about the String created in the String pool with
String s = "abc" ..Then it would be available for garbage collection only after class in which this method is declared is unloaded.
I agree. Here's the link:
subject: Garbage Collection
jQuery in Action, 3rd edition