finalize() is one of the 9 methods in java.lang.Object class. The api docs for the function state:
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
it doesn't do anything by default but it gives you an interception point if you want to perform some action
this is the implementation of finalize()
in java.lang.Object
protected void finalize() throws Throwable { }
The general contract of finalize is that it is invoked if and when the JavaTM virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.
See Also
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With