Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) 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: 10763
148
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).
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!