• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Out Of Memory Error

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic