Sunday, May 20, 2018

What are Finalizer Methods

Leave a Comment
We have seen that a constructor method is used to initialize an object when it is declared. This process is known as Initialization. Similarly, Java supports a concept called finalization, which is just opposite to initialization.

We know that Java run-time is an automatic garbage collecting system. It automatically frees up the memory resources used by the objects. But objects may hold other non-object resources such as file descriptors or window system fonts. The garbage collector cannot free these resources. In order to free these resources we must use a finalizer method. This is similar to destructor in C++.

The finalizer method is simply finalize() and can be added to aany class. Java calls that method whenever it is about to reclaim the space for that object. The finalize method should explicitly define the tasks to be performed.
If You Enjoyed This, Take 5 Seconds To Share It


Post a Comment