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 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 Soft Skills 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
Author

GC-can someone replyto this post?

sanjana narayanan
Ranch Hand

Joined: Nov 25, 2003
Posts: 142
Hi,
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?
-Sanjana
[ January 16, 2004: Message edited by: sanjana narayanan ]
Jessica Sant
Sheriff

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: http://aspose.com/file-tools
 
subject: GC-can someone replyto this post?