3

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?

sethu
  • 8,181
  • 7
  • 39
  • 65
  • 2
    *"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."* Apparently, and that something lies in the lines of code that are different in the real app. Are any threads started in the real code? Do the contents of the tabs have dependencies on other code? Does other code hold references to objects in the tabs? – Andrew Thompson Sep 22 '13 at 08:14
  • Thats what I was trying to analyse using the Heap Dump and it came out that the JPanel was referenced only by the JTabbedPane. If I have called remove on the JTabbedPane why is the heapdump saying that JTabbedPane still hold a reference to it? And to answer the other questions.. as far I can see, no.. there are no references of the JPanel held anywhere else. – sethu Sep 22 '13 at 08:18
  • another issue could be opened Objects, contens filling data to view, somthing like as FileIO, JDBC, etc.... have to check if all file, stream .... readers or resultsets are closed in finally block, btw not possible to answering this question – mKorbel Sep 22 '13 at 11:35

0 Answers0