Hello fellow developers, This is again, about the famous "external allocation too large for this process" Out of Memory exception when loading Bitmaps into your memory. The problem revolves around the following error message:
1502400-byte external allocation too large for this process. Out of memory: Heap Size=5123KB, Allocated=2481KB, Bitmap Size=11183KB VM won't let us allocate 1502400 bytes I've been doing some simple tests and I just can't seem to figure out what the "Bitmap Size" means. The bit of code which generates the above error is as follow: I call the following line (nothing else, this is my main call): Bitmap bitmap = loadBitmap(resources.getDrawable(R.drawable.map_image), Config.RGB_565); Bitmap bitmap1 = loadBitmap(resources.getDrawable(R.drawable.map_image), Config.RGB_565); Bitmap bitmap2 = loadBitmap(resources.getDrawable(R.drawable.map_image), Config.RGB_565); [...] Bitmap bitmap9 = loadBitmap(resources.getDrawable(R.drawable.map_image), Config.RGB_565); about 10 times The map_image has the following dimensions: 1565x480 So it's using up 1502.4kb of memory: 1565*480*2/1000 (*2 => RGB_565) The loadBitmap function used in the above few lines will call the following function: static public Bitmap loadBitmap(Drawable drawable, Config bitmapConfig) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); long sizeStart; long size; Bitmap bitmap; sizeStart = Debug.getNativeHeapAllocatedSize(); bitmap = Bitmap.createBitmap(width, height, bitmapConfig); size = Debug.getNativeHeapAllocatedSize() - sizeStart; System.out.println("Created : " + bitmapConfig.toString() + " : " + size/1000 + " Kb, " + bitmap.getWidth() + "x" + bitmap.getHeight()); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, width, height); drawable.draw(canvas); return bitmap; } Now when I run the code, I will get about 5 calls to the loadBitmap: Created : RGB_565 : 1503 Kb, 1565x480 Created : RGB_565 : 1503 Kb, 1565x480 Created : RGB_565 : 1503 Kb, 1565x480 Created : RGB_565 : 1503 Kb, 1565x480 Created : RGB_565 : 1503 Kb, 1565x480 Before getting the dreaded: 1502400-byte external allocation too large for this process. Out of memory: Heap Size=5123KB, Allocated=2481KB, Bitmap Size=11183KB VM won't let us allocate 1502400 bytes Now I understand that 1502400 bytes is the memory needed to load a new bitmap. I'm guessing that the 5123+2481KB represent (approximately) the 5 previously loaded bitmaps (7604/5=1520.8) But what in god's name is that Bitmap Size value? what is using up those 11 megs? My subsequent question is: In theory I should be able to load 10 times that 1.5 mb bitmap in my memory (before I reach the 16mb limit) why am getting an exception after the fifth bitmap? Thank you very much for any reply or leads you might be able to give me, Regards, -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en