0

I'm resizing an array of bitmaps. Although the array loads fine (indicating there's enough memory to hold it) when I resize (shrink) the bitmaps stored in the array I encounter an OutOfMemory error. Here's the code that resulted in running out of heap:

for (int i=0;i<2;i++) {
    for (int j=0;j<427;j++) {
      frameSet[i][j] = Bitmap.createScaledBitmap(frameSet[i][j],128,128,true);
    }
}

In an attempt to fix the problem I created a temporary bitmap, and added a recycle() call:

for (int i=0;i<2;i++) {
    for (int j=0;j<427;j++) {
        tempFrameResize = Bitmap.createScaledBitmap(frameSet[i][j],128,128,true);
        frameSet[i][j] = tempFrameResize;
        tempFrameResize.recycle();
    }
}

This corrects the OutOfMemory error, but the contents of frameSet are no longer correct (i.e. they appear to be all white, as if the contents of the bitmap were cleared). Does it make sense that my recycle call, called after the contents of tempFrameResize have been passed into frameSet, would affect the contents of frameSet? That seems to be what's happening.

1 Answers1

0

When you assign the scaled bitmap to the array you are not copying the object. You are referencing to it. It's like any other object instance. So you are recycling the scaled bitmap itself amd the one assigned to the array. It's the same object. You are not experiencing heap errors because you are releasing the bitmap array images.

drusilabs
  • 133
  • 10