I have a photo editing app. When I import an image, it works fine but, opening up the image for editing causes it to crash.
This is the logcat output:
08-04 20:56:16.973: E/dalvikvm-heap(336): 810000-byte external allocation too large for this process.
08-04 20:56:17.073: I/dalvikvm-heap(336): Clamp target GC heap from 25.289MB to 24.000MB
08-04 20:56:17.073: E/GraphicsJNI(336): VM won't let us allocate 810000 bytes
UPDATE::
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK
&& null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
ImageView imageView = (ImageView) findViewById(R.id.ivPhoto);
chosenBitmap = superDecodeFile(new File(picturePath));
imageView.setBackgroundColor(0);
Bitmap bMap = Bitmap.createScaledBitmap(chosenBitmap, 500, 500, true);
imageView.setImageBitmap(bMap);
}
}
this is my onResult code .. so the choosenBitmap displays on the imageView ( ivPhoto )
I need to use .recycle();
so i free up some memory by recycling the already imageView ..
where do I use the .recycle(); ?
I tried to change the .setBackgroundColor(0); to .recycle(); but it doesn’t work
This is a memory leak error.
Your app is allocated a heap of size ~24MB. But the image you are trying to edit is larger than the heap size.
This is happening because you are not freeing up the memory. Android’s Dalvik VM does not take care of
GC-ing the native memory used by the app. So, when dealing with images in Android, you need to explicitly userecycle(). This frees up the native memory.For more deatils: Changing ImageView content causes OutOfMemoryError