Exception on finalize ()?

If Exception occurs in finalize() what happened to garbage collector? It will run or not? Explain

Questions by chinmayananda

Showing Answers 1 - 12 of 12 Answers

coolpintu

  • Sep 29th, 2009
 

When the garbage collector calls the finalize() method, it will ignore any exceptions thrown by the finalize() method. In all other cases, normal exception handling occurs when an exception is thrown during the execution of the finalize() method, that is, exceptions are not simply ignored. Calling the finalize() method does not in itself destroy the object.

yrk_in

  • Oct 21st, 2009
 

There is no Guaranty execution of finalize() method because, it will execute just before the garbage collected. But for every application Garbage collection will not be done.
when it will be collected we dont know.

  Was this answer useful?  Yes

There is a finalizer thread which is a background thread and that has a runFinalizer method which skips all the exceptions thrown by invokeFinalizeMethod which internally calls the finalize method of Object to clean. That's why there is no impact on GC if finaliza throws the exception

nagmuthu

  • Dec 7th, 2009
 

Actually when the finalize method throws th exception the object will not be garbage collected,but the next time the object came for a GC it will not call the finalize method and do the G-Cltn for the object , because the finalize method will be invoked only once.

  Was this answer useful?  Yes

If a finalize method throws any exception, then the execution of the finalize method is halted and the object remains eligible for garbage collection. This doesn't mean that it will never be garbage collected. Whenever garbage collection runs again, the object will (actually might) be garbage collected. So basically the exception is ignored and the object is garbage collected.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions