This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Out Of Memory Error" Watch "Out Of Memory Error" New topic
Author

Out Of Memory Error

Satheesh Thekku Veethil
Greenhorn

Joined: Jan 31, 2002
Posts: 25
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
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
Greenhorn

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?
Sat
Joe Cheng
Greenhorn

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.
http://www.onjava.com/pub/a/onjava/2002/10/02/javanio.html?page=3
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Out Of Memory Error
 
Similar Threads
Easy way to copy a file?
Suggestion for filter saving
Problem with images
how to increase/decrease the heap size in java in windows
HTTP Session variable