JDK-5052169 : memory leak triggered by use of Component$NativeInLightFixer
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_7
  • CPU: generic
  • Submitted: 2004-05-24
  • Updated: 2005-12-01
  • Resolved: 2004-10-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b08Fixed
Related Reports
Relates :  
Description
The following test case causes the JVM to run out of Java heap space.
One leak seems to involve the use of NativeInLightFixer.  The test
is constructed to cause Component.removeNotify() calls but not
NativeInLightFixer.componentRemoved() calls.

----

import java.awt.*;

public class Fixer {
    static public void main(String args[]) {
        Frame fr = new Frame("Test Frame");
        Window win = new Window(fr);
        win.show();

        Panel panel = new Panel();

        Component c1 = new Canvas();

        Container c0 = new Container();
        panel.add(c0);
        c0.add(c1);

        while (true) {
            win.add(panel);
            win.remove(panel);
        }
    }
}

----

The problem shows up under 1.5, 1.4.2, 1.3.1, and 1.2.2.

###@###.### 2004-05-24

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang FIXED IN: mustang
01-10-2004

SUGGESTED FIX Name: aaR10319 Date: 05/28/2004 First, add uninstall() method to NativeInLightFixer that removes its as a ComponentListener and ContainerListener from all lightweight and nearest heavyweight parents: final class NativeInLightFixer implements ComponentListener, ContainerListener { ... + void uninstall() { + if (nativeHost != null) { + removeReferences(); + } + } ... } // end of NativeInLightFixer Second, call this method in removeNotify() to perform a cleanup: public void removeNotify() { ... + if (nativeInLightFixer != null) { + nativeInLightFixer.uninstall(); + } ... } // end of removeNotify() ======================================================================
01-10-2004

EVALUATION Name: osR10079 Date: 05/24/2004 In fact, NativeInLightFixer.componentRemoved() shouldn't be called in this test, because NatveInLightFixer listents for ContainerEvent on all containers up to (including) first heavyweight one. But the test removes panel (which is first heavyweight container of canvas) from window, so we shouldn't receive event about it (such event will occur on window, not on panel). ====================================================================== Name: aaR10319 Date: 05/27/2004 Really, when a nativeInLightFixer is created it make itself a ContainerListener on all parents up to the first heavyweight one. So if we remove a component that is higher in the component hierarchy than that first heavyweight container nativeInLightFixer wouldn't be notified about it. Next time a addNotify() method called we create a NEW instance of NativeInLightFixer and the old one remains alive because it is a ContainerListener on some parents. So we should perform a nativeInLightFixer 'cleanup' on removeNotify() and use only one instance of NativeInLightFixer ###@###.### 2004-05-27 ======================================================================
27-05-2004