GC.FM
'finalize()' method should not unregister listeners
Description
This rule flags code where the `finalize()' method unregisters listeners.
The 'finalize()' method only gets called when there are no more references to the object. If the listeners are removed in the 'finalize()' method, the object will not be removed during garbage collection.
Example
package GC;
import java.awt.Panel;
import java.awt.Button;
public class FM extends Panel {
public void finalize() {
remove (_button); // violation
super.finalize();
}
private Button _button = new Button();
}
Repair
Do not call methods that remove listeners in the 'finalize()' method body.
|