• 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

finalize method

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,, i am very much confused about how finalize() method works since there is very less explanation about this method.
can anyone help me out in explaining that in the following the defined object is eligible for garbage collection, If it is, how? and if not why? or will it ever be able to get collected by garbage collector as there exists a live ref reffering to the object.. please help in explaining the story behind the scenes..


thanks.
regards.
 
Ranch Hand
Posts: 109
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi arpit,

finalize() method is using to declare codes that needs to run before some object delete from memory by the garbage collector. But it's not guaranteed whether finalize() method runs or not by GC. Because Garbage collectors actions are unpredictable.

If we manually invokes finalize() method form some object therefor garbage collector will not invoke finalize() method when it delete that object.
But if we not invoke finalize() method manually and we add code into finalize() method that pass reference to that object into another objects reference variable we can protect that objects deletion at least once.

It's not happen because of a miracle in finalize() method. It happens because it's passed reference to this object into another object. Then garbage collector knows that and avoid deletion of that object because garbage collector is not delete objects that have references.

I think I explain it correctly..
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic