finalizeto always reclaim resources. Instead, if an object has resources which need to be recovered, it must define a method for that very purpose - for example a
closemethod, or a
disposemethod. The caller is then required to explicitly call that method when finished with the object, to ensure any related resources are recovered.
With JDK 7+, the try-with-resources
feature can be used to reclaim resources for
any object that implements
For an extensive discussion, please see the "Avoid Finalizers" topic in Effective Java.
method is deprecated.