Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage collection

 
Rainer ?hman
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic