File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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: 9462

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 agree. Here's the link:
subject: GC for string pools
It's not a secret anymore!