• Post Reply Bookmark Topic Watch Topic
  • New Topic

JPEGImageEncoder OutOfMemoryError  RSS feed

 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • 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
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!