Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4389043

JMenu memory leak

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.3.1_03
    • 1.3.0
    • client-libs
    • 03
    • x86
    • windows_nt



        Name: yyT116575 Date: 11/14/2000


        java version "1.3.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
        Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

        The attached program includes a JMenuBar with a JMenu in it. Clicking on
        the "Remove" button should cause the JMenuBar and the JMenu to become garbage.
        The JMenuBar does become garbage, but the JMenu does not. I do not have any
        poitners to it, they're all from JDK (BasicMenuUI$PostAction,
        BasicMenuUI$ChangeHandler, SwingPropertyChangeSupport, etc).

        --- code ---
        import javax.swing.*;
        import java.awt.event.*;

        class Test {
          JFrame f;
          JMenuBar mb;
          JMenu menu;
          
          Test () {
            f = new JFrame("TEST");
            mb = new JMenuBar();
            menu = new JMenu("Test Menu");
            mb.add(menu);
            f.setJMenuBar(mb);
            JButton b = new JButton("Remove");
            f.getContentPane().add(b);
            b.addActionListener(new ActionListener () {
                public void actionPerformed (ActionEvent e) {
                  disposeMenu();
                }
              });
            f.pack();
            f.show();
          }

          private void disposeMenu () {
            f.setJMenuBar(null);
            mb.remove(menu);
            menu = null;
            mb = null;
            f.validate();
          }

          public static void main (String[] args) {
            new Test();
          }
        }
        (Review ID: 112246)
        ======================================================================

              svioletsunw Scott Violet (Inactive)
              yyoungsunw Yung-ching Young (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: