Finalization in Java:
finalize()-
in a typical c++ class,any memory that is dynamically allocated for the data members of the class, have to be explicitly released by the programmer. to enable this, c++ as a language provides te syntax of 'destructor' which will be automatically called when ever the object is about to destroyed. In the destructor the programmer has to access all its data members and hence can release any explicitly allocated memory.
In Java , the concept of destructor was never provided as the destruction of an object,is not in the control of programmer and is completely managed by the garbage collector. Java hence provides the concept of 'finalize method' defined in the base class object that can be overridden by any of the derived classes. The finalize method of an object will be automatically called whenever the garbage collector is about to destroy the current object. How Ever it is recommended by oracle not to relay on the garbage collector, since the call of it is not guaranteed. Instead, the programmer must provide his own mechanism of releasing resources. this process of releasing the resources is done by 'finalize()' method.
Note: '()'-denotes method.
finalize()-
in a typical c++ class,any memory that is dynamically allocated for the data members of the class, have to be explicitly released by the programmer. to enable this, c++ as a language provides te syntax of 'destructor' which will be automatically called when ever the object is about to destroyed. In the destructor the programmer has to access all its data members and hence can release any explicitly allocated memory.
In Java , the concept of destructor was never provided as the destruction of an object,is not in the control of programmer and is completely managed by the garbage collector. Java hence provides the concept of 'finalize method' defined in the base class object that can be overridden by any of the derived classes. The finalize method of an object will be automatically called whenever the garbage collector is about to destroy the current object. How Ever it is recommended by oracle not to relay on the garbage collector, since the call of it is not guaranteed. Instead, the programmer must provide his own mechanism of releasing resources. this process of releasing the resources is done by 'finalize()' method.
Note: '()'-denotes method.
No comments:
Post a Comment