What is the purpose of finalization?Finalization is the facility to invoke finalized() method. The purpose of finalization is to perform some action before the objects get cleaned up. This method performs the required cleanup before the garbage collection, which means the elimination of the ‘orphan objects’.
Finalization is provided by Java for classes that use native resources to perform clean up before the objects are subjected to garbage collection.
The native resources are beyond the control of Java's garbage collector. The responsibility of cleaning up the native allocations depends on the object's finalization code.
Finalization is done so that the native resources are not left in the memory even after the Java instances are terminated by garbage collection.
|