Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Eligible for GC  RSS feed

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is Q36 in MindQ's SCJP Test.

36. How many objects are eligible for garbage collection once execution has reached the line labeled Line A?




a) 0
b) 1
c) 2
d) 3
e) 4

The answer that they provide is b) 1.

My argument is that since all the assignments are made to the string objects in the string pool rather than heap, none of the objects will be eligible for GC till the class is unloaded. So I prefer to choose (a)

Any opinions?
 
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I disagree with that reasoning. If there are no strong references to any of those strings, there is no need to keep them interned.
 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dont worry I dont think questions like these are going to be on the exam, Mr. Bert Bates said so himself not too long ago.
And you know what that means...This would also make a great interview questions
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mr. C Lamont Gilbert
If there are no strong references to any of those strings, there is no need to keep them interned.



I agree with Mr Lamont.
Neelesh:
Since String literal pool also contains objects(of strings), there is no reason why they cannot be garbage collected if there are no strong references ?
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strings, Literally


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.

 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!