finalize() function : Garbage collectors delete objects when it has no reference pointing to it. Your object can has finalize () function. It is called before destroy of the object. This function is used to free any resource that is in use of the object. Finalize () function is a member Object class. As you should already know any class in java is inherited from object class. You can override the finalize function and specify what your object do before it destroy. There is no guarantee to invoke garbage collectors, hence no guarantee for finalize method to be called. So it is a good programming to free resource when you will not need it again When object has reference it is called unfinalized and when it has no reference is it is called finalizer reachable, because it can be only accessed in the finalize () function.
example :
- Code:
protected void finalize() {
// clean up code
}