Garbage Collection
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
String name;
String newName = "Nick";
newName = "Jason";
name= "Fried";
String newestName = name;
name = null;
//LINE A
a) 0
b) 1
c) 2
d) 3
e) 4
Answer b
This is right? why?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
When you get to LINE A:
newName refers to "Jason"
newestName refers to "Fried"
nothing refers to "Nick", so its eligible for garbage collection.
By the way, since "Nick" is in the String Literal Pool, which isn't garbage collected, the answer may be "a".
Mike Gershman
SCJP 1.4, SCWCD in process
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
When line A is reached, the variable newName refers to String object "Jason", newestName refers to "Fried" and name refers to null. The object "Nick" has no variable referencing it. Hence only this object is eligible for GC.
Seema Manivannan<br />Author and Trainer: Java Certifications<br /> <br />Whizlabs Software<br />Success, certified!<br />Global leader: J2EE certification exam preparation!<br /><a href="http://www.whizlabs.com" target="_blank" rel="nofollow">http://www.whizlabs.com</a><br /> <br />An ISO 9001-2000 certified company!
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Seema Manivannan<br />Author and Trainer: Java Certifications<br /> <br />Whizlabs Software<br />Success, certified!<br />Global leader: J2EE certification exam preparation!<br /><a href="http://www.whizlabs.com" target="_blank" rel="nofollow">http://www.whizlabs.com</a><br /> <br />An ISO 9001-2000 certified company!
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I'll bet my money on a for that reason.
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Prashanth R<br />Chennai
| I am Arthur, King of the Britons. And this is a tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |






