• 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

Quick Q concerning GC

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well tomorrow is the big day.
But before then, I have a quick question regarding garbage collection.
If you explicitly call the finalize() method of an object, will the system still invoke the method right before destroying it.
I'm asking this because I've read that the finalize method is only called once. Does this mean only the system calls it once?
What if the object is resurrected during the execution of its finalize method. when it becomes eligible for garbage collection again will its finalize method be called yet again?
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jimmy Blakely:
Well tomorrow is the big day.
But before then, I have a quick question regarding garbage collection.


Good luck!!!


If you explicitly call the finalize() method of an object, will the system still invoke the method right before destroying it.


If you explicitly call finalize it will execute as a normal method and not release any memory. It will still be executed when the object is destroyed.


What if the object is resurrected during the execution of its finalize method. when it becomes eligible for garbage collection again will its finalize method be called yet again?


Yes
The following code shows your first example:

hope that helps
Dave
SCJP
 
Jimmy Blakely
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Muchos Gracias
 
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What if when the system calls finalize() when destroying an object, in the finalize() method, the object is assigned to a reference, hence rendering it not eligible for GC?
 
reply
    Bookmark Topic Watch Topic
  • New Topic