• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

finalize help plzzz

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have written a small code. When the program is over, the finalize function should be called. But it is not calling that one. You can have a look in my code.

According to me it should print "The object is going to be deleted" three times. But it is not printing.
Please help me out.
Thankz in advance.

Arnab

(You too can use [C0DE][/C0DE] tags )
[ October 09, 2004: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not believe that the garbage collection will run automatically (and hence not your finalize method). If may not run even if you ask it to do so (kind of like trying to teach a cat to sit). I was able to get the output you are looking for with the following slightly modified code:

Note that although I have asked for the garbage collection to execute, it may not. At the very least, you have to provide some objects to be available for garbage collection before the application is finished which is what I have done by setting the object references to null.

Does this help?
 
ArnabKarmakar karmakar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you,
its working.
But can we always run the gc successfully whenevr we want.

arnab
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can call System.gc() whenever you wish, but you cannot be sure that all eligible objects will be garbage collected, if any.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic