java.lang.OutOfMemoryError: Java heap space
Hi,
I am new to this forum.
I just finished making an image processing tool for my college project by manipulating the image pixels.
Small size images up to 600-700 kb are loaded properly, but when when I try to load an image with size greater than 1 Mb it gives error.
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
at GetImage.getImagePixels(GetImage.java:109)
at GetImage.loadImage(GetImage.java:86)
at First$2.actionPerformed(First.java:120)
I tried increasing the heap size of jvm but still the same error.
XX:MaxPermSize=128m
-Xms128m
-Xmx1024m
Please help.
Thanks
Re: java.lang.OutOfMemoryError: Java heap space
That is pretty expected, if you're doing things like storing millions of Objects based on each pixel of a large image. I'd look at modifying your algorithm to be as efficient as possible (this is one of the few cases I actually recommend bothering with optimization). Alternatively, you could also try saving stuff out to a file- but I'd try the optimization route first.
Re: java.lang.OutOfMemoryError: Java heap space
Thanks kevin for replying....I didnt get it though.What kind of optimization are you suggesting?.is there anything else you could suggest.
I am using a 3D array for storing pixels and then manipulating those pixels to get the required effect.
Re: java.lang.OutOfMemoryError: Java heap space
Without knowing your algorithm, I can't really tell you how to optimize it.
The thing is, even with optimization, if you're storing all of the pixels (why a 3D array?), you're going to run out of memory with sufficiently large images. Perhaps you could work with the pixels one row at a time, or even one at a time, instead of storing them all at once?
Re: java.lang.OutOfMemoryError: Java heap space
To add to Kevin's post, a single pixel for an 8 bit image can be stored in a single int primitive, (rgba - one byte for each value - access the values using bit operations), and all pixels for an image in a single 1D or 2D array. When one starts creating different ways to store these values that require larger data types/structures, you will more easily run into memory problems with larger image.
Re: java.lang.OutOfMemoryError: Java heap space
Re: java.lang.OutOfMemoryError: Java heap space
Re: java.lang.OutOfMemoryError: Java heap space
No problem. Did you get it figured out?