Garbage Collection

Java handles deallocation automatically.

And the automated deallocation is called garbage collection.

When no references to an object exist, and that object is eligible for garbage collection

The finalize( ) Method

The Java calls finalize( ) method whenever it is about to recycle an object.

finalize() is called just prior to garbage collection.

The finalize( ) method has this general form:

protected void finalize( ) 
    // finalization code here 

The keyword protected prevents access to finalize( ) by code defined outside its class.

  Java Book