• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about GC

 
Sundar Murthi
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..

I found following one in mindQ mock exam??



How many objects are eligible for garbage collection once the execution has reached at label LineA.

The Ans Given as : 1

But regarding to string literals no one is garbage collectable.
so my ans is 0

is it ok???

kinly show some light on this.

tx in adv
 
Shilpi M Ag
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sundar

Yes I think you are right... We had a similar discussion some days back - http://www.coderanch.com/t/245614/java-programmer-SCJP/certification/GC-String

And the conclusion everyone found was that literals dont get garbage collected...Altho I was myself not very well convinced of the same... However I had accepted it.. But now this 2nd case (urs) has again made me think, if literals also get garbage collected!

Lets wait and see what everyone else has to say abt it!
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Literals are stored in the String pool which is not subject to regular garbage collection.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The good new is, you're right. The answer should be 0. There are no objects eligible for Garbage Collection in that example. String literals are not eligible for garbage collection and, in that example, that's all you have.

The better new is that this is not on the SCJP exam. You'll have to answer questions about garbage collection, but you won't have to answer questions about Sting literals in terms of garbage collection.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic