It is better to avoid using finalization to clean up any resources other than Java (call completion is not guaranteed). If possible, use a try with resources (when using JDK7) or finally try suggestions to clear resources, among other parameters, if possible. If you intend to use finalize, you can put super.finalize in a finally try block. It would be wise not to rely on completing the cleanup of resources.
If the idea is to clear the resources, it would be reasonable, perhaps, to check phantom links - an object is phantom accessible if it is not very / weakly / mildly reachable, it has been completed and there is at least one phantom link (i.e. an object has been completed but not yet restored).
ali haider
source share