This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes about GC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "about GC" Watch "about GC" New topic
Author

about GC

Sundar Murthi
Ranch Hand

Joined: Mar 05, 2004
Posts: 209
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

Joined: May 07, 2004
Posts: 40
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

Joined: Oct 12, 2000
Posts: 5093
Literals are stored in the String pool which is not subject to regular garbage collection.


42
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
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.


SCJP Tipline, etc.
 
GeeCON Prague 2014
 
subject: about GC