File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Performance and the fly likes Out Of Memory Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Out Of Memory Error" Watch "Out Of Memory Error" New topic

Out Of Memory Error

Satheesh Thekku Veethil

Joined: Jan 31, 2002
Posts: 25
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.
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
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
Posts: 25
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?
Joe Cheng

Joined: Feb 23, 2003
Posts: 11
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.
I agree. Here's the link:
subject: Out Of Memory Error
It's not a secret anymore!