Why do we need a finalze() method when Garbage Collection is there

Showing Answers 1 - 7 of 7 Answers

Kandukuri Ravinder

  • Aug 8th, 2005
 

finalize() method is used to release the resources which were previously allocated for that object before the object is going to be Garbage Collected

meenama

  • Apr 30th, 2008
 

We need not call the finalize() method directly. The method is called automatically by the garbage collector when it determines no more references to the object exist. But when we need to clean-up non-Java resources ie closing a file, we need to over-ride this method from java.lang.Object in our class implementation.

  Was this answer useful?  Yes

By using finalization,we can define specific actions that will occur when an object is just about to reclaimed by the Garbage Collector.
e.g - If an object is holding some nonjava resources such as file handling or window character resources it need to be freed before the object is get destroyed.To handle this kind of situation finalize() method is called though there is Garbage Collector.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions