A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Arduino in Action
this week in the
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
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).
I agree. Here's the link:
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: immutable String objects
Problem with String and StringXxx objects
Doubt in Garbage Collection
generics question (sample mocks)
Garbage collect with String Objects
is this object eligible for garbage collection??
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013