File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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
It's not a secret anymore!