• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Finalization Method

 
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regarding Finalization Method:
If an uncaught exception is thrown during the finalization, the exception is ignored and finalization of that object terminates.
My Question is what happens next to the object?
After the finalization terminates, does the objects get destroyed or it does nothing??
Sonir
 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The object gets reclaimed by the GC, only the finalization process is aborted at the point the "uncaught" exception occurs in the finally clause.
--
Rajinder Yadav
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sonir :
Was your question in reference to the finally block of code or was it in reference to the finalize method, which is typically called by the garbage collector after the object is no longer accessible from any reference?
 
sonir shah
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
finalize() method..
??
 
Shivaji Marathe
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought so too. Your question has nothing to do with the finally block. Finalization can happen on objects that do not have any try/catch/finally blocks at all.
This is what the API states of finalize method


The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.
After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.


I believe this means,that even if an exception occurs in the finalize method, the object still remains eligible for garbage collection and it will be garbage collected eventually.
HTH
 
Rajinder Yadav
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess I read the question wrong, so to clear up my original reply
If the uncaught exception occurs in the clean up of the object's finialize() method then the current execution of the program is aborted, but the exception is ignored!
btw, there is nothing preventing a try/catch/finally block from appearing within a finalize method.
[ January 21, 2002: Message edited by: Rajinder Yadav ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic