This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage Collection" Watch "Garbage Collection" New topic

Garbage Collection

Aleix Vellozo

Joined: Aug 23, 2006
Posts: 2
Hi all,

I am a bit confused with the answer for Question 3 on Dan Chilsholm website:

Which old object is he referring to here, q1 was initially set to null before the loop, so at this point no objects are eligible for gc right?

Any comments on why the answer is 9, I would appreciate. Is it because all the 9 objects created will be eligible for gc when main() exit?

wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
There are 10 Q objects created by for loop.
"When the processing of line 2 begins", there are 9 objects eligible for GC and one is still hold by q1.
Aleix Vellozo

Joined: Aug 23, 2006
Posts: 2
Thanks Wise,

I thought I had gc worked out but it seems not.

Why is the last object refereced by q1 not eligible for gc?

I agree. Here's the link:
subject: Garbage Collection
Similar Threads HashMap Question
A question from -
Garbage Collection Problem Explain Pls Dan Chisholm single topic
Garbage collection...