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.