File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

gc question

 
Yosi Hendarsjah
Ranch Hand
Posts: 166
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From Dan Chisholm's mock:

Question: When the processing of line 2 begins, how many objects of type Q that were created at line 1 are eligible for garbage collection?
Answer: 9
Is it possible that before the for loop ends, some of the object of type Q have already garbage collected so when System.gc() is invoked the number of objects of type Q left are less than 9?
 
Kristof Camelbeke
Ranch Hand
Posts: 97
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my opinion I don't think so because you can only make objects eligible for GC in these cases : 1) Nulling a Reference (q1 = null; )
2) Reassigning a ref. variable (q1 = q2);
3) Isolating a ref.
 
David Hadiprijanto
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Yosi,
I think you are right that some of the 9 objects created in line 1 might have been garbage collected before the loop ends.
But for the sake of the exam, I think the answer is indeed 9.
The SCJP exam expects us to know when such objects are eligible for GC, not when they are actually garbage collected. The keyword here is eligible.
So, I think the wording in Dan's exam is already correct, and the answer is 9.
Just my 2 cents.
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yosi,
If I remember correctly, the real exam uses the words "are eligible". It would be more correct to use the words "have become eligible", because that would include those that have already been garbage collected. The next version of my exam will use the more correct wording.
Does anyone object to the new version?
 
David Hadiprijanto
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It would be more correct to use the words "have become eligible", because that would include those that have already been garbage collected.

Sounds like a better ambiguity-eliminator to me.
Dan, I admire your commitment to provide high quality SCJP mock exam.
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you David.
Congratulations on your 100% score on the real exam!
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic