• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

statement regarding the garbage collector?

 
sura watthana
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic