File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes GC-can someone replyto this post? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "GC-can someone replyto this post?" Watch "GC-can someone replyto this post?" New topic

GC-can someone replyto this post?

sanjana narayanan
Ranch Hand

Joined: Nov 25, 2003
Posts: 142
During finalization of an object, if an exception is raised, the exception is ignored and the object is not garbage collected. IS this stmt true for all types of exceptions(caught/uncaught) or(checked/unchecked). I got a small program to understand this stmt but got confused. can someone help me?
[ January 16, 2004: Message edited by: sanjana narayanan ]
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

from Khalid/Mughal's 1st edition pg 252
The automatic garbage collector calls the finalize method in an object which is eligible for garbage collection before actually destroying the object....A finalizer can catch and throw exceptions like other moethods. However, any exception thrown but not caught by a finalizer when invoked byt the garbage collector is ignored. The finalizer is only called once on an object, regardless of being interrupted by any exception during its execution. In case of finalization failure, the object still remains eligible to be disposed of at the discretion of the garbage collector (unless it has been resurrected).

from the JLS: 12.6 Finalization of Class Instances
If an uncaught exception is thrown during the finalization, the exception is ignored and finalization of that object terminates.

So, from what I've read above I belive ANY UNCAUGHT exception (checked or unchecked) can cause teh finalization to fail. That being said, I wouldn't stress over this for the exam.
Just knowing the basic facts like these should be enough:
* uncaught exceptions will be ignored
* that the finalize() method is only called once
* finalize() methods are not automatically chained.
[ January 16, 2004: Message edited by: Jessica Sant ]

- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
I agree. Here's the link:
subject: GC-can someone replyto this post?
jQuery in Action, 3rd edition