SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD, SCEA/OCMJEA
Live life to an interface, not an implementation!
A reference to that String object will be retained in the runtime constant pool, as with other String literals.One String object will be eligable for garbage collection, "Nick".
One String object will be eligible for collection i.e. "nick"
code:
--------------------------------------------------------------------------------
Object v1; Object v2 = new Object(); // <-- o1 v2 = new Object(); // <-- o2 v1 = new Object(); // <-- o3 Object v3 = v1; v1 = null; //Line A
--------------------------------------------------------------------------------
Jignesh Raval
Originally posted by Kanchan K Bulbule:
As per your example reference to Nick is lost
" String newName = "Nick";
newName = "Jason"; "
So "Object Nick " is available for Garbage Collection
it looks like String and Object are different in Garbage Collection?
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|