• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Exception thrown in finalize method

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read the API regarding finalize method but i'm unable to understand the following line

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.


Can someone explain what does this exactly mean. As per my understanding the exception will be ignored but the object will not be garbage collected. So, does this mean the object will never be garbage collected?
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well Arvind, 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. Here's a test program

 
Aarav Thomas
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Ankit!
 
reply
    Bookmark Topic Watch Topic
  • New Topic