• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GC for string pools

 
Peter Heide
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter Heide
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ankit Garg for your answer, I think you are absolutely right!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic