• 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

Restoring an object in finalize() ?

 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Part of an explanation concerning garbage collection was given as:
"An object that has been eligible for garbage collection may stop being eligible and return to normal life. This occurs if the call to the finalize() method re-establishes a reference from the active part of the program to the object."
Can someone provide an example of this in a finalize method? I'm not clear how an object once eligble now could become eligible.
Thanks.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess the following code snippet demonstrates the concept:

Output:
Test object after creation:Test@17d257
Test object before resurrection:null
Test object after resurrection:Test@17d257
HIH
 
Rick Reumann
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Valentin,
I was thinking that with the statement
t=this
in the finalize method that the JVM would see this and wouldn't try to even garbage collect it in the first place after it was set to null in the main. I see now that I was wrong thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic