• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Swing performance

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
In a fairly large Swing applications, lots of Swing objects gets created and destroyed. Let's assume there is a form in an application that has about 300 widgets (including JTabbedPane, JTextField, JLabel, JButton, ...). Each time this form gets created in the application, we have to create all these widgets. Although when we dispose the JFrame holding these widgets, theoretically they become available for the garbage collector to clean up, we want to make sure they get cleaned up as fast as possible (as this could harm the performance of our application if they stay around too much). If I am right, we can call the System.gc(), but even this call does not force the garbage collector to run at that time. Is this correct?
Any thoughts on how to improve performance in this scenario?
Thank you,
Payam.
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If possible, keep the form around but not visible. Each time it is displayed, repopulate it with relevant data, and make it visible again.
You're right, calling System.gc() does not absolutely guarantee the garbage collector will run. It's just a suggestion, which the JVM can ignore if it chooses.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a good idea to use the approach mentioned above for the most used forms, but you might not want to use it for rarely used ones. An option is to call System.gc() when you are already showing a progress indicator onscreen. That way the user will not notice the slowdown, it will just seem that the operation is a bit slower.
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
300 objects is not so much.
I would not be attempting to manipulate the VM's garbage collection to dispose of 300 objects.
If there is a JTabbedPane, you might consider delaying the creation of each pane until the user activates the pane. In other words, group each tab page into a JPanel (or some component) and don't populate the child components until the ChangeListener tells you that the page has been activated.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic