This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage Collection" Watch "Garbage Collection" New topic
Author

Garbage Collection

Sonal Ray
Ranch Hand

Joined: Mar 15, 2005
Posts: 56
Hello,
Can anybody tell me what will happen if uncaught exception occurs in finalilze() method?

I got the following from API
"...If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates. ..... Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored".

Does it mean that the object will NOT be eligible for garbage collection now,may be later some othertime it will be Garbage collected without calling the finalize() again (as finalize() can be called only ONCE for that object)?
Animesh Shrivastava
Ranch Hand

Joined: Jul 19, 2004
Posts: 298

Does it mean that the object will NOT be eligible for garbage collection now,may be later some othertime it will be Garbage collected without calling the finalize() again (as finalize() can be called only ONCE for that object)?

Yeah absolutely, it means that the garbage collection for that object terminates but still the object remains eligible and will be garbage collected sometime later, without calling finalize() all over again.
deshdeep divakar
Ranch Hand

Joined: Apr 19, 2004
Posts: 91
Every Exception that is uncaught are handeled by Default Exception
Handler,regardless it is thrown in try block or finilally.As per my
knowledge of JLS


"Do not be afraid of going slow, be afraid of standing still"
deshdeep divakar
Ranch Hand

Joined: Apr 19, 2004
Posts: 91
Sorry the reply is
Every Exception that is uncaught are handeled by Default Exception
Handler,regardless it is thrown in try block or finilize.As per my
knowledge of JLS
deshdeep divakar
Ranch Hand

Joined: Apr 19, 2004
Posts: 91
Sorry the reply is
Every Exception that is uncaught are handeled by Default Exception
Handler,regardless it is thrown in try block or finalize.As per my
knowledge of JLS
Nikhilesh Fonseca
Ranch Hand

Joined: Aug 23, 2004
Posts: 57
Does the Finalisze method terminate"NOramlly" or is it Halted...if it throws an uncaught exception..
Animesh Shrivastava
Ranch Hand

Joined: Jul 19, 2004
Posts: 298

Does the Finalisze method terminate"NOramlly" or is it Halted...if it throws an uncaught exception..

The finalize method gets halted. But the object is still eligible for GC and can be collected at a later stage
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
And when later , it will be collected at this time finalize() method will get called or not ...

I think not , otherwise again exception , then interrupt , and again object will not collected ...

Right ?

Thanks .
Animesh Shrivastava
Ranch Hand

Joined: Jul 19, 2004
Posts: 298
No it will not get called, it will just collect the object because finalize() can be called only once for any object
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Thanks Animesh .
When you are giving exam .
I think you are well prepared at this time also .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage Collection
 
Similar Threads
finalize method
finalize and finalizer : Need clarification
finalize method question
GC-can someone replyto this post?
closing file from finalize() and explicitly calling finalize()