File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GC-can someone replyto this post?

 
sanjana narayanan
Ranch Hand
Posts: 142
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4313
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic