aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes finalize help plzzz Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "finalize help plzzz" Watch "finalize help plzzz" New topic
Author

finalize help plzzz

ArnabKarmakar karmakar
Greenhorn

Joined: Oct 04, 2004
Posts: 5
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 ]
Chris Allen
Ranch Hand

Joined: Feb 01, 2003
Posts: 127
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

Joined: Oct 04, 2004
Posts: 5
thank you,
its working.
But can we always run the gc successfully whenevr we want.

arnab
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
You can call System.gc() whenever you wish, but you cannot be sure that all eligible objects will be garbage collected, if any.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
Consider Paul's rocket mass heater.
 
subject: finalize help plzzz