问题
I have added a few tabs to a JTabbedPane. Each tab contains a JPanel. I now remove the tab by calling JTabbedPane.remove([tab index]). This removes the tab and everything is fine, except that when I profile the app, the JPanel added to the JTabbedPane does not get 'disposed' off and the reference is still present in the heap. After few 100 operations of adding the tab and closing it, the app goes Out of Memory.
I analysed the heap dump using Eclipse MAT and I clicked on the Immediate Dominators of the JPanel that shouldn't have been there after closing the tab. The Immediate Dominator came back as the JTabbedPane.
So then I wrote an SSCCE to reproduce the problem and found I couldnt reproduce the issue. When I close the tab, the JPanel does get disposed off. Is there something I am missing. Why would a JTabbedPane hold on to references to a JPanel even after closing the tab in some cases?
Update:
I was looking at the MAT histogram in bit more detail and came across something queer.
This is the snapshot of the heap dump when the tab is open. The below is the correct hierarchy of the classes. The HomeFrame contains a JTabbedPane which contains a MasterDataDisplayPanel which contains a ShareholderDtlsPanel. Also please note the hashcode of the object ShareholderDtlsPanel - ..a20.
This is the image that shows the state after closing the tab. The hashcode of the ShareholderDtlsPanel is different ..b340 and its getting associated to a PropertyChangeListener which is completely unrelated.
Could someone help me understand what's happening here? Is this a swingx JXTaskPaneContainer bug maybe?
来源:https://stackoverflow.com/questions/18941575/how-to-dispose-a-tabbed-pane-component-completely-from-a-jtabbedpane