Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strings- Garbage Collection

 
Sharmili Rameshbabu
Greenhorn
Posts: 27
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Considering the below code,



Does the object pointed by two in line 1 eligible for garbage collection at the end of the main method?
Is it eligible only after doing two=two.intern()?
Are string literals in heap never eligible for garbage collection since there is always a reference to it from the String Literal Pool ?
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This excellent article will answer all your questions, so read it carefully. If you are still in doubt, feel free to post your questions/doubts.

Disclaimer: the intern method is not on the OCAJP exam (it isn't even on the OCPJP exam).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic