JComboBox memory leak: does not unregister itself from its model

XMLWordPrintable

      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.

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: