Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to dispose internal component asynchronously?

843806Apr 25 2008 — edited Apr 29 2008
Hi all,
I'm currently investigating (using profilers - jconsole* and jhat+) my code to remove all the memory leaks.
This way, I already succeeded to de-reference lots of objects and that lead to some very good results at the end...
... but I still have one last problem:

Normally, when a JPanel is disposed (*dispose()* method called), then all internal components are disposed and de-referenced so that the memory is freed. It works pretty well on all swing components. If you dispose - or simply if you stop using - one JPanel containing a lots of inner JPanels, JLabel etc. all of them will be properly freed when the GC decides to run).

But I'm using in some of my swing panels the excellent JDateChooser class (from the JCalendar package). The problem is that JDateChooser is not freed automatically! I've seen that the author added in v1.3.2 a cleanup() method so that the user can call it manually when needed to free the resources but I don't understand how/when I can call this method in my case:

If I simplify a bit, my GUI is composed of a horizontal splitpane gathering a left panel and a right panel. When you click on some some stuff in the left panel, it builds a new right Panel and replace the old one this way:
splitPaneHorizontal.setRightComponent(newRightPanel.getCore());
splitPaneHorizontal.revalidate();
As I said if all the components in the right panel are regular swing widget, no problem. the fact to update the right panel with a new one, free all the resources of the old one. I suppose that when I call setRigthComponent() it starts by calling dispose() on the old right panel then add the new one.

Anyway... I don't know when the right panel will be disposed (so when I should call the cleanup() on all the JDateChooser's in the right panel). Do one of the Java gurus here could explain how I could "trigger" the manual cleanup of all the JDateChoosers in the right panel being replaced?
Thanks a lot in advance,
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 27 2008
Added on Apr 25 2008
12 comments
465 views