Jtest logo




Contents  Previous  Next  Index

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.


Contents  Previous  Next  Index

ParaSoft logo
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft