• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

exit of an object

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

How to find whether an object has exited or not?
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

How to find whether an object has exited or not?[/B]
Actually what is the meaning of this question.
whether an object has gone out of scope / or gc'd.
If this is the case put some println statement in finalize method
of the object. you will cometo know when it is about to be gc'd.
Sasidhar
 
sasi dhulipala
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by amit sanghai:

How to find whether an object has exited or not?


put some thing in its finalize method
This should work.
Sasidhar
 
sasi dhulipala
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I am sorry I see that the println statement in side finalize is not working .. But I assure you that you can put yr clean up code inside finalize method . And this would definitely be called before the object is garbage collected. Hope I have not confused you too much.
Sasidhar
 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi sasi,

Q1) Why does the println() function does not work inside finalize method() ?
Q2) I meant object is out of scope? I think that you cannot find out whether an object is available for garbage collection. Is that true?
 
sasi dhulipala
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by amit sanghai:

Hi sasi,

Q1) Why does the println() function does not work inside finalize method() ?
There seems to be some twist here. See the API doc
"protected void finalize()
throws Throwable
Called by the garbage collector on an object when garbage collection determines that there are
no more references to the object. A subclass overrides the finalize method to dispose of
system resources or to perform other cleanup. "
What above means is that finalize is called when the object has already gone out of scope( and at this point of time it is at the mercy of the gc to be started by OS) that is why println method is not working. if we call explicitly the finalize method it is working. No more references means it is out of scope of all methods .

Q2) I meant object is out of scope? I think that you cannot find out whether an object is available for garbage collection. Is that true?


some times you can make finalize method to resurect the ( about to be garbage collected object )object.
to sum it all (as you said ): once an oject is out of scope( of all the reference to it ) we can say it has become ready for garbage collection. but when it is gc'd ( i.e exited ) exactly cannot be known.
sasi
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic