aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes statement regarding the garbage collector? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "statement regarding the garbage collector?" Watch "statement regarding the garbage collector?" New topic
Author

statement regarding the garbage collector?

sura watthana
Ranch Hand

Joined: Sep 13, 2004
Posts: 77
Hi,
I came across a statement from a book regarding garbage collector but i don't really understand what the author is trying to say. so could somebody tell me what it means, thanks.

code

A finalizer can, like any other method, catch and throw exceptions/*** this sentence i understood, the rest i really don't ***/. However, any exception thrown but not caught by a finalizer invoked by the garbage collector is ignored. The finalizer is only called once on an object, regardless of whether any exception is thrown during its execution. In case of finalization failure, the object still remains eligible for disposal at the discretion of the garbage collector (unless it has been resurrected, as explained in the next subsection).
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982

A finalizer can, like any other method, catch and throw exceptions/*** this sentence i understood, the rest i really don't ***/. However, any exception thrown but not caught by a finalizer invoked by the garbage collector is ignored.

You can do anything, such as clean up in this method. Thus, runtime exception, such as NullPointerException, can still be thrown. The finalizer is usually invoked by GC, and GC will NOT caugh such exceptions. Thus, exceptions are ignored if they are not handled by the finalizer itself.


The finalizer is only called once on an object, regardless of whether any exception is thrown during its execution.

Finalizer will only be called once, and usually, we will not invoked it in our code. It will be called by GC, but it is NOT assured by the JVM, as well as the specification.


In case of finalization failure, the object still remains eligible for disposal at the discretion of the garbage collector (unless it has been resurrected, as explained in the next subsection).

Even there are exceptions encountered in the finalizer, the object will still be a candidate for being GC.

Nick


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: statement regarding the garbage collector?