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

JComboBox memory leak: does not unregister itself from its model

    XMLWordPrintable

Details

    Description

      Once JComboBox.setModel(model) is called the JComboBox registers itself to the passed ComboBoxModel but never unregisters. So if the passed model is static (shared) model the JComboBox is held forever and thus a container holding it ... and whole chain of references. Was discovered with leak in NetBeans where whole project is never garbage collected due to this leak. Easy workarounds exist once one discover the culprit. See attached artifical testcase and try to watch the heap with e.g. jhat. If you uncomment the alternative "leakingCombo" with overriden removeNotify() the leakingCombo gets GCed - so this is also proposed fix: override removeNotify in JComboBox and remove the listener there.

      Attachments

        Issue Links

          Activity

            People

              bchristi Brent Christian
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: