1

I'm having problem while trying to create a BufferedImage. I have this problem just on the server I rented, not on my development environment (my computer).

I have a form to upload image. After the image is uploaded I save it to the file system. I save it immediately because, according to what some of you said, I can "release" resources from the server memory, since I use the image on my file system and not the object Part to make the image resizes, controls, etc. I need.

As soon as I try to create a BufferedImage, from an image bigger than 2-3 mb, I get that error.

While executing this line my Application stop working and I get that error

BufferedImage immagineTemporaneaBufferizzata = ImageIO.read(new File...);

I used a method found on the internet to check the memory on the server. This is what I get before encountering the error:

Used Memory:26 Free Memory:30 Total Memory:57 Max Memory:57

Should I increase the heap memory? I tried to do it both on catalina.bat and catalina.sh but I didn't see changes in my Max Memory. Probably I did something wrong. What's the right way to increase heap size on linux?

MDP
  • 4,177
  • 21
  • 63
  • 119
  • 1
    I cannot find read method of ImageIO, which accepts String as argument. – mkrakhin Sep 01 '14 at 10:50
  • [Increase Tomcat memory settings][1] [1]: http://stackoverflow.com/questions/12688778/increase-tomcat-memory-settings – Sumit Jhajharia Sep 01 '14 at 11:01
  • possible duplicate of [How to deal with "java.lang.OutOfMemoryError: Java heap space" error (64MB heap size)](http://stackoverflow.com/questions/37335/how-to-deal-with-java-lang-outofmemoryerror-java-heap-space-error-64mb-heap) – Andremoniy Sep 01 '14 at 11:06
  • @mkrakhin i make an error while writing my post, there is a file not a String in my real code – MDP Sep 01 '14 at 12:00

1 Answers1

1

Max memory 57 MB is frankly quite low for Java applications processing images with 2-3 MB. Yes, you should definitely increase the memory if you can.

To clarify: Image size 2-3 MB. What is this 2-3 MB? The size of the compressed image? If it is a JPG with 2-3 MB, that can be hell of a big image (depending on the quality). E.g. it might even be an image of 3200x2000 pixels which is 6.4 million pixels, and with 3 byte RGB pixel model it would be ~20 MB of binary data in memory.

About increasing tomcat memory see these questions:

Dealing with "java.lang.OutOfMemoryError: PermGen space" error

Increase Tomcat memory settings

Community
  • 1
  • 1
icza
  • 389,944
  • 63
  • 907
  • 827
  • Thank you for your explanation. I'm not familiar with image resize and i didn't know what really happen when i resize an image. I check the image i was uploading. it is 4896x1890; this means that, according to what you said, my site is handling a 27 mb binary stream. Now im wondering how big sites like facebook can handle the uploading of thousands of pics at the same moment. – MDP Sep 03 '14 at 08:18