I'm having some trouble understanding why this code
public class BitmapAllocTest extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); byte[] b = new byte[20 * 1000 * 1000]; b = null; Bitmap.createBitmap(2500, 2000, Bitmap.Config.ARGB_8888); } }
throws an OutOfMemory exception on a device with a 24mb heap limit. If I comment out either of the allocations it runs fine. I was under the impression that the java vm would try to garbage collect before throwing OutOfMemory exceptions.
I suspect it having to do with android allocating the bitmaps on the native heap.