Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

gc question

 
Ranch Hand
Posts: 168
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you David.
Congratulations on your 100% score on the real exam!
 
reply
    Bookmark Topic Watch Topic
  • New Topic