Manning's Countdown to 2014
. Use discount code crdotd14 all month for 50% off every deal.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
immutable String objects
Joined: Dec 28, 2004
Jan 11, 2005 02:33:00
A newbie question
Say if I have a
String s = "nothing special"; //line1
s = s.toUpperCase(); //line2
Now the s object reference in line2 is a new one & different from the 1 created initially at line1 as Strings are immutable objects
My question is what happens to the previous String object (s) in this case
Joined: Apr 14, 2004
Jan 11, 2005 02:48:00
It still exists in memory, though now there is no reference pointing to it so you can't use it, and presumably it will get Garbage Collected at some time.
Joined: Oct 12, 2000
Jan 11, 2005 04:45:00
Strings in the String object pool don't typically get garbage collected unless the pool runs into capacity problems (in which case the JVM can decide to do something, possibly based on last access time).
It is sorta covered in the
JavaRanch Style Guide
subject: immutable String objects
Doubt in Garbage Collection
is this object eligible for garbage collection??
Problem with String and StringXxx objects
Garbage collect with String Objects
generics question (sample mocks)
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013