Query with regards to exorbitant Memory usage by Swing.
843811Mar 28 2004 — edited Apr 16 2004Hi there.
We are currently struggling with JVM memory usage under the Swing Toolkit, specifically with regards to opening multiple instances of a complicated JDialog or JFrame in short space (views onto database records, each dialog has approximately 500 fields that have to be populated and displayed, lurking on several tabbed panes, and no, we cannot alter this behaviour). Firstly, each dialog is consuming inordinate amounts of memory (sometimes up to 15 megabytes), and none of this is GC'd once the dialog is displayed. Secondly, when the dialog is closed, this memory is not immediately liberated, but trickles out over the next five minutes (we assume due to the actions of the garbage collector).
Given the nature of the application, this is not acceptible behaviour - we need to be able to spawn off multiple instances of this JDialog in quick succession without worrying about not having enough free memory to do so. Enabling incremental garbage collection made the problem even worse, if that was possible, since even less memory was 'reclaimed'.
We have moved to a model where we attempt to reuse each JDialog or JFrame instead of spawning a new one, but this has given no relief. I am currently in the process of placing explicit close() methods on each subcomponent of our screens that will explicitly set any internal hashmaps, vectors etc to null after emptying them, but I suspect that this will be a drop in the ocean since I'm of the opinion it's actually a Swing-wide problem with regards to liberating memory from unused or disposed graphics components. We've been struggling with this problem for several years now, through several releases of the JRE. Sun has claimed several times that the memory management of the JVM has been improved, but we've honestly seen no improvement on our side.
Does anyone here have any suggestions? Or is this just something we'll have to live with? Short of giving the process more memory on startup, which isn't always feasible, we've run out of ideas. (I've even tried native calls to the windows frame-minimisation method mentioned in bug # 4412569 ( see http://developer.java.sun.com/developer/bugParade/bugs/4412569.html )
Thanks for your time.
McF