John Jared
John Jared

Reputation: 800

Image Processing: "dalvikvm: external allocation too large for this process" error

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

Upvotes: 1

Views: 3951

Answers (2)

Frohnzie
Frohnzie

Reputation: 3569

Your image is too large to load into memory. Unfortunately you cannot change the maximum amount of memory your application uses. See Displaying Bitmaps for detailed information about loading and displaying bitmaps.

Upvotes: 0

Sagar Hatekar
Sagar Hatekar

Reputation: 8790

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 use recycle(). This frees up the native memory.

For more deatils: Changing ImageView content causes OutOfMemoryError

Upvotes: 3

Related Questions