A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Programmer Certification (SCJP/OCPJP)
Garbage collection question
Joined: Jun 12, 2005
Aug 11, 2006 14:07:00
Could anybody give answer of this question...
How many objects are eligible for garbage collection once execution has reached the line labeled Line A?
String newName = "Nick";
newName = "Jason";
name = "Frieda";
String newestName = name;
name = null;
I expected it is zero, as string literals do not garbage collected and remain on string pool instead of heap.
Joined: Jun 26, 2006
Aug 11, 2006 16:52:00
I think in Your Code ,
the Nick Object will be eligible for the garbage collection.Because although
"nick" is a string literal,an "nick" object is also created in the heap.
Please Correct me if iam wrong.
Joined: Feb 02, 2006
Aug 11, 2006 18:07:00
I agree. Here's the link:
subject: Garbage collection question
garbage collection question
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014