"java.lang.OutOfMemoryError: Java heap space" in image and array storage

Posted by totalconscience on Stack Overflow See other posts from Stack Overflow or by totalconscience
Published on 2010-06-03T18:16:05Z Indexed on 2010/06/03 18:24 UTC
Read the original article Hit count: 189

Filed under:
|
|

I am currently working on an image processing demonstration in java (Applet).

I am running into the problem where my arrays are too large and I am getting the "java.lang.OutOfMemoryError: Java heap space" error.

The algorithm I run creates an NxD float array where: N is the number of pixel in the image and D is the coordinates of each pixel plus the colorspace components of each pixel (usually 1 for grayscale or 3 for RGB). For each iteration of the algorithm it creates one of these NxD float arrays and stores it for later use in a vector, so that the user of the applet may look at the individual steps.

My client wants the program to be able to load a 500x500 RGB image and run as the upper bound. There are about 12 to 20 iterations per run so that means I need to be able to store a 12x500x500x5 float in some fashion.

Is there a way to process all of this data and, if possible, how?

Example of the issue: I am loading a 512 by 512 Grayscale image and even before the first iteration completes I run out of heap space. The line it points me to is:

Y.add(new float[N][D])

where Y is a Vector and N and D are described as above. This is the second instance of the code using that line.

© Stack Overflow or respective owner

Related posts about java

Related posts about image-processing