File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why Donot finalize method run? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why Donot finalize method run?" Watch "Why Donot finalize method run?" New topic
Author

Why Donot finalize method run?

Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643


In above code the finalize method donot run
i am not able to understand why.

Thanks
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
You have implemented finalize in your Test class. You do not create an instance of your Test class. So no instance of the Test class needs to be garbage collected (or rather, is eligible for garbage collection)


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643
But there are Integer objects inside for loop which should be garbage collected.
Awais Sheikh
Ranch Hand

Joined: Jun 07, 2006
Posts: 48
Hello,
Finalize method is called when object of a class is created and completes its work, but remember finalize method should in the class whose garbage it has to be collect.
In your code you implemented in the test class, but no where object of Test class is created so this finalize method will not called by gc. new Interger is calling finalize method of Integer class not Test class. Try the code below hope it will clear you.



Thanks
Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643
Thanks Awais Sheikh
Now i understood it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why Donot finalize method run?
 
Similar Threads
AutoBoxing
Sun's mock question 4.
overriding question
Thread/ Exception
Garbage collection output doubt