React-native-image-crop-picker: Android: OutOfMemoryError crash when adding many items from picker

Created on 12 Jul 2017  路  3Comments  路  Source: ivpusic/react-native-image-crop-picker

Version

Tell us which versions you are using:

  • react-native-image-crop-picker v0.14.0
  • react-native v0.45.1

Platform

  • Android

Expected behaviour

Images are returned from the following API call, similar to how they are on iOS.

return ImagePicker.openPicker({
    multiple: true,
    mediaType: 'photo',
   includeBase64: true,
});

Actual behaviour

When adding many items (reliably crashes with 10+ on Samsung Galaxy S7), the app pauses for a moment and then crashes to the menu.

Steps to reproduce

  1. Open an Image Picker on Android.
  2. Attempt to add 15 images at once.
  3. Observe crash.

Attachments

07-12 17:25:46.744 4205-4275/com.myappnamegoeshere W/art: Throwing OutOfMemoryError "Failed to allocate a 150583044 byte allocation with 16777216 free bytes and 24MB until OOM"
07-12 17:25:46.878 4205-4275/com.myappnamegoeshere W/art: Throwing OutOfMemoryError "Failed to allocate a 150583044 byte allocation with 16777216 free bytes and 24MB until OOM"

                                                         --------- beginning of crash
07-12 17:25:46.879 4205-4275/com.myappnamegoeshere E/AndroidRuntime: FATAL EXCEPTION: mqt_js
    Process: com.myappnamegoeshere, PID: 4205
    java.lang.OutOfMemoryError: Failed to allocate a 150583044 byte allocation with 16777216 free bytes and 24MB until OOM
        at java.util.Arrays.copyOf(Arrays.java:3352)
        at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:130)
        at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:114)
        at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:417)
        at java.lang.StringBuffer.append(StringBuffer.java:237)
        at java.io.StringWriter.write(StringWriter.java:101)
        at java.io.StringWriter.append(StringWriter.java:143)
        at com.facebook.react.devsupport.JSDebuggerWebSocketClient.executeJSCall(JSDebuggerWebSocketClient.java:133)
        at com.facebook.react.devsupport.WebsocketJavaScriptExecutor.executeJSCall(WebsocketJavaScriptExecutor.java:181)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
        at android.os.Looper.loop(Looper.java:154)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:199)

Most helpful comment

Update, fixed!!

when picking multiple, remember don't set this lineincludeBase64: true in openPicker
this will cause outofMemory issue on Android
if you need base64 data, use sth like FileSystem.readFile(image.path, 'base64') in .then()

Anyway hope this will be fixed soon

All 3 comments

Update: I've tried adding android:largeHeap="true" to my AndroidManifest.xml, as per https://stackoverflow.com/a/42212814

This results in the Promise throwing an error: length=1; index=1

Is this an issue for android? I run this code on Nexus 6 (3GB ram)
ImagePicker.openPicker({ multiple: true, maxFiles: 15, includeBase64: true, mediaType: 'photo' }).then(res => { console.log('res', res); })
choose about 7 photo (about 16MB) and my app crash showing out of memory
but on ios it works fine

Update, fixed!!

when picking multiple, remember don't set this lineincludeBase64: true in openPicker
this will cause outofMemory issue on Android
if you need base64 data, use sth like FileSystem.readFile(image.path, 'base64') in .then()

Anyway hope this will be fixed soon

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tximpa91 picture tximpa91  路  3Comments

equesteo picture equesteo  路  3Comments

jmahatpure01 picture jmahatpure01  路  3Comments

manojshrimalla picture manojshrimalla  路  3Comments

victorwpbastos picture victorwpbastos  路  3Comments