• 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

JPEGImageEncoder OutOfMemoryError

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there

I am busy writing some code that will compress images.

On the screen, the user can see their original image on the left hand side, and the result of the compression operation on the right hand side.

Now in my code, I get an OutOfMemoryError at the same line of code every time at encode.encode(...)



The other thing that concerns me is that the steps taken to reproduce this error are
1 - open image
2 - compress image
3 - rotate image
4 - compress image
And the app will get the OutOfMemoryError on step 4.

I would very much appreciate it if someone could help me out. I have read that a solution is to increase the JVM heap size, but I fear that this will just mean that while it will make the current image work, a larger and larger image will break it anyway.

Many kind regards,
Rachel
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trying to figure out java imaging memory problems is painful. There's just not a lot of control or feedback from the image subsystem. One thing you can try is to invoke flush() on your BufferedImage instance before setting it to null. That SUPPOSEDLY frees the associated resources, but I've had mixed results using it. Set your virtual machine to have a huge heap as well. Images are extremely memory-intensive.
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joe

Thank you for the reply.

I have tried to flush out everything I possibly can, which helped to a point, I guess now all that is left is to up the heap size.

Many thanks!
Rachel
 
No more fooling around. Read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic