Overriding the Object.finalize()
method must be done with caution to dispose some system resources.
Calling the super.finalize()
at the end of this method implementation is highly recommended in case parent implementations must also
dispose some system resources.
Noncompliant code example
protected void finalize() { // Noncompliant; no call to super.finalize();
releaseSomeResources();
}
protected void finalize() {
super.finalize(); // Noncompliant; this call should come last
releaseSomeResources();
}
Compliant solution
protected void finalize() {
releaseSomeResources();
super.finalize();
}