GeeCON Prague 2014*
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
Author

Garbage collection

Rainer ?hman
Greenhorn

Joined: Nov 01, 2002
Posts: 1
Hi all!
My first posting on this list with a tiny question:
Going through books and mock exams, I find some difference concerning at what point an object is eligable for garbage collection.
Questions of type: At what line... sometimes is referred to the line 4 in:
4. ref = null;
5.
and sometimes to line 5.
What gives?
- Rainer
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

Originally posted by Rainer �hman:
Questions of type: At what line... sometimes is referred to the line 4 in:
4. ref = null;
5.
and sometimes to line 5.
What gives?

I'd say the answer should be "after line 4" -- that's how it was written in Mughal's book, and that's how it was written when I took the real exam.
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Howdy, I agree with Jessica -- the real exam will say "after line 4", or in some possible situations, "at line 5", rather than "at line 4" which would be ambiguous.
The wording on the exam for these questions is clear, although sometimes you do not see all the code, so you might see something like:
public void foo() {
1. Object o = new Object();
2. o = null;
3. // more code here
}
And the you'd need to know that "after line 2" but *before* the method completes, the object created on line 1 is eligible.

Cheers,
Kathy


Co-Author of <a href="http://www.amazon.com/exec/obidos/ASIN/0596007124/ref=jranch-20" target="_blank" rel="nofollow">"Head First Design Patterns"</a><br /> <br />Just a Jini girl living in a J2EE world.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Garbage collection