Why Do We Use finalize Method in Java ?

Java provides finalize() method to perform any cleanup before Garbage Collection. This method is in Object class, and it is invoked by JVM internally. Developers are free to implement this method for any custom cleanup in case of Garbage Collection.

If an Object is not Garbage Collected, then this method may not be called.

This method is never invoked more than once by JVM.



You May Interest

How Will You Implement ApplicationContext in Spring Framework ?

Does Java Allow Virtual Functions ?

What are the Advantages of Using JSP in Web Architecture ?

What is the Reason to Organize Classes and Interfaces in a Packag ...

Why ListIterator Has add Method But Iterator Does Not Have in Jav ...