Course Content‎ > ‎Session 5‎ > ‎

Finalize Method

A constructor method is used to initialize an object when it is declared. This process in called initialization. In the same way, there is a concept of finalization in Java, which is opposite to initialization. Java run-time is an automatic garbage collecting system. It automatically frees up the memory resources used by the objects. But if objects hold other non-object resources such as file systems, window system fonts, the garbage collector cannot free these resources. In order to free these resources, we must use a finalize method (finalize method is similar to destructors in C++).

The finalize method is simply written as:

    finalize( );

Simply add finalize method to any class. Java calls this method, whenever it is about to reclaim the space for that object. 

Comments