When are String Literals Garbage Collected?
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Does anyone know when a String literal that exists in the string pool is garbage collected, if ever?
Thanks
Dan
Thanks
Dan
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
A string literal is never GC, since it was not created on the heap.
Bosun
Bosun
Bosun (SCJP, SCWCD).
So much trouble in the world -- Bob Marley
Dan Temple
Ranch Hand
Posts: 93
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Ah ... right! What a stupid question on my part.
Thanks
Dan
Thanks
Dan
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Not at all. Everything seems easy after you know how it works!
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
But if a string literal is never GC:ed (or removed in some other way), couldn't that lead to out of memory if you create a lot of large temporary Strings?
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
You should distinguish between String literals - which are part of the code - and String objects - which are constructed at run time, allocated on the heap and GCd like any other object.
- Peter
- Peter
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Andreas Johansson
Ranch Hand
Posts: 43
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Guess I'm a bit confused here... What exactly is a string literal then?
Bosun Bello
Ranch Hand
Posts: 1514
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Andrea...
String a = "String Literal"
String b = new String("String Object");
A string literal is not created with the new keyword.
Bosun
String a = "String Literal"
String b = new String("String Object");
A string literal is not created with the new keyword.
Bosun
Bosun (SCJP, SCWCD).
So much trouble in the world -- Bob Marley
Andreas Johansson
Ranch Hand
Posts: 43
posted 24 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Of course... Simple as that. =) I think I made it more complicated then neccesary.
And I hope that you just missed the 's' in Andreas, I'm not a girl, you know. ;-)
Thanks anyway
/Andreas
And I hope that you just missed the 's' in Andreas, I'm not a girl, you know. ;-)
Thanks anyway
/Andreas
| We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |






