• 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

Garbage collection.. finalize () Method

Ranch Hand
Posts: 148
Hibernate Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have some questions about accessing the object in the finalize () Method.

1.Who is responsible for calling the finalize () Method in java programs.

2.If JVM calls the finalize () Method ,then on which object the method is being called(its not a static method).Is it the same object which needs to be garbage collected?

3.If its the same object(which need to be GC),then is following statement is true?

The object cannot be garbage collected until and unless the finalize () Method is being called.

4.Can I reuse the object for which the finalize () method is runing ,so that to avoid its GC?


Posts: 9691
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. JVM
2. Yes
3. Well sort of, the JVM might not be able to call finalize method on your object if the JVM session ends before your object is garbage collected.
4. Yes you can, you can assign the this reference to a static variable to create a reference for your object in which case it will not be garbage collected. But when it does, the finalize method would not be called again...
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic