Sunday 15 August 2010

Needed RAM to display images in java -


Another perceptual question .. I'm fighting against a Java heap space exception. My problem is, that I have to render / must be displayed smaller, but many images over maximum RAM (edit vm option does not help), but still I store all the images in a list. I think if I present the images one by one and I need less RAM to temporarily store it on the local hard disk, then I think. What images will be in Ram even when it is displayed on the screen?

Changes in code will be important, so I want to ask before.

If there is a lot of images / icons in a JList / JTable inside JScrollPane in case of your use, then I once wrote something for displaying the results of the CMS search:

I have large stored on server Images were cached on thumbnails / disks You can take advantage of the fact that JLIT / JT (or swing components in general) will only try to paint components that are visible on the screen, so you do not have to track yourself. I used a jlabble with the image icon as a renderer in the list, and a fixed size cache of the mouse in the memory. Whenever the renderer did not hit an image in the cache, I used a lazy-loading technique in which a placeholder icon was returned immediately, while the icon was loaded in the background using swingwalker. On loading, Swingworker republished for JLIS. The icon will now be in the cache, and this list will paint well.

Some bonus tips: Make sure your icon is more than the maximum number of items that can be displayed on the cache screen. In addition, use a limited (fixed size) thread pool for your swingwalkers (possibly several icons are being loaded at a time), avoid the XISAP repeat-loop for.

No comments:

Post a Comment