Bookmark Topic Watch Topic
  • New Topic

How to overcome OutOfMemory error?

 
Giorgos Christoulas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,
I am developing a Java application for processing satellite images.
The size of every image is 2000*2000 pixels. When I try to set the pixel
values into an int array I get an OutOfMemory error.
Here is a portion of my code:
PlanarImage originalImage = JAI.create("fileload",imagePath);
Raster originalRaster = originalImage.getData();
SampleModel originalSampleModel = originalImage.getSampleModel();
int width = originalImage.getWidth();
int height = originalImage.getHeight();
int bands = originalRaster.getNumBands();
int length = width*height;
int originalPix[][] = new int[bands][];
for (int b =0;b<bands;b++)
originalPix[b] = new int[length];
for(int band = 0; band < bands;band++)
originalPix[band] = originalSampleModel.getSamples(0,0,width,height,band,originalPix[band],originalRaster.getDataBuffer());
Is there a limit on the number of elements an array can have?
I have set the memory heap size to 160MB (-J -Xmx160m) but the results are the same.
Note that this part of the code will be implemented in a GUI
My system has physical memory 1024MB
Does anyone knows how to overcome this problem?
Thanks in advance
Giorgos
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Report post to moderator
Is the value of each pixel really an int? I'm wondering if the range of values is limited enough you could put them in bytes or shorts or something smaller. See types & ranges here: http://www.surfscranton.com/architecture/JavaDataRanges.htm
 
Giorgos Christoulas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Stan.
The method ....getSamples(...) returns only int ot double arrays.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't post the same question in multiple forums. Since you've been getting many responses in the Performance forum, I'm closing this thread now; please post any followups to the other thread.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!