File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collection question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage Collection question" Watch "Garbage Collection question" New topic
Author

Garbage Collection question

Jeff Schuler
Greenhorn

Joined: Apr 17, 2007
Posts: 23


When "e3 = null;", does that set e3.e to null as well? If not why? It can no longer be referenced. So after "e3 = null;", isn't their one object available for GC?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Jeff Schuler:
... When "e3 = null;", does that set e3.e to null as well? If not why? ...

It does not set the e3.e reference to null. However, the object that e3.e is pointing to can no longer be reached, and this makes it eligible for garbage collection.

But there is a problem with this code. At runtime, it will throw a NullPointerException at the line e2.e = e1; At that point, e2 is already null, so e2 cannot be dereferenced to get to e2.e.
[ July 28, 2007: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Jeff Schuler
Greenhorn

Joined: Apr 17, 2007
Posts: 23
Originally posted by marc weber:

It does not set the e3.e reference to null. However, the object that e3.e is pointing to can no longer be reached, and this makes it eligible for garbage collection.

But there is a problem with this code. At runtime, it will throw a NullPointerException at the line e2.e = e1; At that point, e2 is already null, so e2 cannot be dereferenced to get to e2.e.

[ July 28, 2007: Message edited by: marc weber ]


Thanks for the reply. This question is referring to a question in K&B book chapter 3. It states that a single object is never eligible for GC even though there is one prior to the runtime exception.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Jeff Schuler:
... This question is referring to a question in K&B book chapter 3. It states that a single object is never eligible for GC even though there is one prior to the runtime exception.

Hmmm... I'm not sure what that means. Did you check the K&B Errata page?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage Collection question
 
Similar Threads
Islands of isolation
garbage collection
How can we determine whether an object's reference variable is null or not?
garbage collection
SCJP......Garbage collection