• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Finalizer Method

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,
This is related to GarbageCollection guaranteed behaviour.

Can we tell like
Once the finalizer of an eligible object is run by GC successfully, will the eligible object is collected by Mr. Garbage Collector immediately after the completion of finalizer.

Correct me if I am wrong with concpet.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually not always. In the finalize() method you can actually make your object inelligible for garbage collection by reestablishing a reference to it.
- You're not guaranteed every object will be garbage collected.
- You are guaranteed that the finalize() method will run on any object that is garbage collected.
- The finalizer will only be run once for any object -- even if the object has been revived.
[ December 17, 2005: Message edited by: Philippe Saint-Just ]
 
Mohan Chandrasekaran
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.

Can you explain
Whether finalizer can throw checked exceptions?
 
Philippe Saint-Just
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored." If there is an exception, you won't see it.

protected void finalize() throws Throwable

check out the API documentation of the finalize() method: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Object.html

[ December 17, 2005: Message edited by: Philippe Saint-Just ]
[ December 17, 2005: Message edited by: Philippe Saint-Just ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic