Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Out of memory error with big images #116

Closed
svajoklis-1 opened this issue Feb 24, 2016 · 4 comments
Closed

[Android] Out of memory error with big images #116

svajoklis-1 opened this issue Feb 24, 2016 · 4 comments
Labels

Comments

@svajoklis-1
Copy link

We are using this library in our project and we are resizing images to {maxWidth: 1024, maxHeight: 1024}. When we try to pick an image that's very large (16 MB in size) the showImagePicker method crashes with:

FATAL EXCEPTION: main Process: com.devbridge.TeamApp2_Android.debug, PID: 2504 java.lang.OutOfMemoryError: Failed to allocate a 203079692 byte allocation with 4194304 free bytes and 53MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.BitmapFactory.nativeDecodeStream(Native Method) at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:635) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:611) at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:391) at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:417) at com.imagepicker.ImagePickerModule.getResizedImage(ImagePickerModule.java:495) at com.imagepicker.ImagePickerModule.onActivityResult(ImagePickerModule.java:400) at com.imagepicker.ImagePickerPackage.handleActivityResult(ImagePickerPackage.java:46)

The issue is not apparent in Android Emulator with enough VM Heap size, but when it's reduced to realistic sizes (64 for example) or when testing on a real device - application crashes as soon as it tries to resize the image.

@yfuks yfuks added the 🐛 Bug label Feb 24, 2016
@yfuks yfuks changed the title [Bug] Out of memory error with big images [Android] Out of memory error with big images Feb 24, 2016
@yfuks
Copy link
Contributor

yfuks commented Feb 24, 2016

Did the crash appears on the first resize ?

Android devices can have as little as 16MB of memory available to a single application.
http://developer.android.com/training/displaying-bitmaps/index.html

If it's on the first resize you need to allocate more memory to your app.
http://stackoverflow.com/a/11275704

A work around is also to not resized the given image

@yfuks
Copy link
Contributor

yfuks commented Mar 3, 2016

No response i close.

@yfuks yfuks closed this as completed Mar 3, 2016
@rahuljiresal
Copy link

This issue still exists. I need the images to be resized so my server API accepts them. But this always crashes while trying to resize them. From what I could tell, its the BitmapFactory.decodeFile(realPath, options) that is the problem.

The solution would be to change the BitmapFactory options as mentioned here --

BitmapFactory.Options options = new BitmapFactory.Options();
 options.inJustDecodeBounds = false;
 options.inPreferredConfig = Config.RGB_565;
 options.inDither = true;

@davidruisinger
Copy link

I was running into the same issue. Adding android:largeHeap="true" to <application> tag in AndroidManifest.xml solved the issue for me on my physical Android but I'm a bit concerned that this might still be an issue for some devices with less memory?!?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants