How to dispose a tabbed pane component completely from a JTabbedPane

纵然是瞬间 提交于 2021-01-27 19:08:01

问题


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.

enter image description here

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. enter image description here

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!