Hello I am developing a Image Viewer Application in Java which can load any number of images. The images are usually 8-9 MB in size. So I run the program with -Xmx option. But the problem is that this limits the number of images that I can load. For exampl with 256M heap size I can load at the most 10-15 images. Is there something wrong here?? Is it possible to change the heap size of JVM at runtime?? Please suggest. Sat
Hmmm. 15 * 9 is only about 135 -- I wonder what's filling up the other half of the heap. What are you doing with all these large images? Since you can't simultaniously view them all at full resolution, it might be possible to discard some of them from memory and re-read from the filesystem as necessary (if you want thumbnail-ish views, creating small copies and discarding the originals might help). Filesystem access tends to be slow, though, and would probably cause a noticable delay to the user. I don't know if this will make any difference, but calling flush() when you're done displaying an image might help. Another idea: Those are some pretty heavy images. Would it be acceptable to show versions with decreased resolution? Based on a quick web search, it seems that other people have run in to problems with very large files. Here's just one example.
Satheesh Thekku Veethil
Joined: Jan 31, 2002
Hi David Thanks for the reply. In fact I need to cache those images in memory for certain reasons. one being that these are modifiable by the user and at any time he may want to view it. There are also options of viewing 4-16 images simultaneously on the same screen. So removing them from memory will be a problem. But i find it strange that JVM cannot dynamically increase the heap size. Any ideas? Sat
The JVM can and does dynamically increase the heap size. Can you look at the process in Task Manager (or top on *nix) and see if it really is hitting 256MB or thereabouts before it dies? If you're using Java 1.4, could you use a memory map? I haven't tried it but I understand it's for exactly this kind of situation. http://www.onjava.com/pub/a/onjava/2002/10/02/javanio.html?page=3