Swing
Swing component caching?
Date: 30 Jun 2003 02:51:43 -0700Newsgroups: comp.lang.java.gui
Size: 1,769 bytes
Hi The software I'm creating defines a number of 'screens' each of which contains various multimedia components (video, audio, images, text areas, buttons, etc). The screens and components are created from an XML descriptor when the software fires up. I've created classes to represent these components, and their job is to manage the Swing resources used to render each component (e.g. a JPanel and ImageIcon for a relatively simple 'image' component). When a screen is initialised (i.e. displayed), each component creates the necessary Swing components and adds them to the main full-screen panel. On a screen change, the components are removed from the screen and disposed with. So currently each component dynamically creates (i.e. new) Swing components each time the screen is visited, and releases them for garbage collection when the screen is done with. Now there are several hundred of these screens each containing on average half-a-dozen components (and therefore generally half-a-dozen Swing components). Does anyone think there would be a performance benefit in caching the Swing components between screens? i.e. maintain a pool of JPanels, JTextPanes, ImageIcons, mouse listeners, etc. rather than creating them dynamically. Obviously I can measure performance now, re-code the various component classes to use caching, and re-measure to see if it helped or not. But this would take a good few hours of development work, and I'd like to see if anyone else has tried anything similar before I start to bastardise my nice design. I've worked on the assumption that creating a couple of thousand (several hundred x half-a-dozen) Swing components up-front would be a bad idea - but is it? Any thoughts, experiences, ideas appreciated. ta - sarge
