Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes GC for string pools Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "GC for string pools" Watch "GC for string pools" New topic

GC for string pools

Peter Heide
Ranch Hand

Joined: Nov 04, 2006
Posts: 31
I am wondering if the Strings in the string pool are getting eligible for garbage collection or are living there until the program ends.

Given the following, is the string s one or two times time eligible?

Ankit Garg

Joined: Aug 03, 2008
Posts: 9400

The SCJP exam doesn't cover GC for String objects. From here

Unlike most objects, String literals always have a reference to them from the String Literal Pool. That means that they always have a reference to them and are, therefore, not eligible for garbage collection.

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Peter Heide
Ranch Hand

Joined: Nov 04, 2006
Posts: 31
Thank you Ankit Garg for your answer, I think you are absolutely right!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: GC for string pools
It's not a secret anymore!