Skip to content Skip to sidebar Skip to footer

Java.lang.outofmemoryerror: Failed To Allocate A 31961100 Byte Allocation With 15257484 Free Bytes And 14mb Until Oom

I am doing scaled a bit map like below Bitmap resizedBitmap = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(picturePath), 960, 730, false); doing this processing i am upload

Solution 1:

This is how you can use BitmapFactory.Options :

final BitmapFactory.Optionsoptions=newBitmapFactory.Options();
options.inJustDecodeBounds = true;
options.inSampleSize = 2;
options.inJustDecodeBounds = false;
options.inTempStorage = newbyte[16 * 1024];

Bitmapbmp= BitmapFactory.decodeFile(picturePath,options);
BitmapresizedBitmap= Bitmap.createScaledBitmap(bmp, 960, 730, false);

Also you can calculate the inSampleSize for your bitmap by writing a custom function.

Here's google documentation : http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

You Can increase the Memory allotted to your application by adding android:largeHeap="true" in manifest.

Note : Increasing heap for your application doesn't considered to be a ideal solution.

Here's the extract from google that explains it,

However, the ability to request a large heap is intended only for a small set of apps that can justify the need to consume more RAM (such as a large photo editing app). Never request a large heap simply because you've run out of memory and you need a quick fix—you should use it only when you know exactly where all your memory is being allocated and why it must be retained. Yet, even when you're confident your app can justify the large heap, you should avoid requesting it to whatever extent possible. Using the extra memory will increasingly be to the detriment of the overall user experience because garbage collection will take longer and system performance may be slower when task switching or performing other common operations.

here's the complete link of the documentation https://developer.android.com/training/articles/memory.html

Post a Comment for "Java.lang.outofmemoryerror: Failed To Allocate A 31961100 Byte Allocation With 15257484 Free Bytes And 14mb Until Oom"