React-native-image-picker: Android: Out of memory when scrolling a lot in gallery

Created on 4 May 2016  路  2Comments  路  Source: react-native-image-picker/react-native-image-picker

Hi, I'm using react-native 0.24.0 and react-natuve-image-picker 0.18.15.
On a One Pus 1, it happens much more often, on a Nexus 5 sometimes.

When I scroll a lot in the gallery the phones crash with the following logcat:

Any idea how to prevent the OutOfMemory error?

05-04 14:23:37.144 11643 15753 D FolderScanner: prescan: 22, used=261
05-04 14:23:37.175 11643 11698 D chenghui: scan folder:/storage/emulated/0/Download,file count=13,expense time=6
05-04 14:23:37.182 11643 11697 D chenghui: scan folder:/storage/emulated/0/Pictures,file count=81,expense time=9
05-04 14:23:37.184 11643 11697 D chenghui: scan folder:/storage/emulated/0/Pictures/VSCO,file count=8,expense time=1
05-04 14:23:37.185 11643 11698 D chenghui: scan folder:/storage/emulated/0/Pictures/VSCOCam,file count=16,expense time=1
05-04 14:23:37.256 11643 11697 D chenghui: scan folder:/storage/emulated/0/DCIM/Camera,file count=864,expense time=57
05-04 14:23:37.258 11643 11643 W Gallery : not found: /storage/emulated/0/DCIM/Camera
05-04 14:23:37.376 11643 11698 D chenghui: scan folder:/storage/emulated/0/WhatsApp/Media/WhatsApp Images,file count=1724,expense time=111
05-04 14:23:37.392 11643 15753 D FolderScanner: scan: 192, used=248
05-04 14:23:37.761 11643 11671 D skia    : --- SkImageDecoder::Factory returned null
05-04 14:23:38.196   779  1365 D WifiService: acquireWifiLockLocked: WifiLock{NlpWifiLock type=2 binder=android.os.BinderProxy@f7b7dd2}
05-04 14:23:38.198   779   909 D wifi    : Initialized common fields 10000, 16, 100, 10
05-04 14:23:38.199   779   909 D wifi    : bucket[0] = 2:3:10000:2
05-04 14:23:38.273 11643 11643 W Gallery : not found: /storage/emulated/0/DCIM/Camera
05-04 14:23:38.536   779   897 D ConnectivityService: notifyType CAP_CHANGED for NetworkAgentInfo [WIFI () - 153]

05-04 14:23:38.813   779  1011 D WifiService: releaseWifiLockLocked: WifiLock{NlpWifiLock type=2 binder=android.os.BinderProxy@f7b7dd2}

05-04 14:23:38.829  2262  2397 D GCoreFlp: FLP HAL exists but batch size is <= 0.  Disabling FLP HAL.
05-04 14:23:41.748   779 19812 D NetlinkSocketObserver: NeighborEvent{elapsedMs=77222702, 192.168.161.250, [3C4A9277C2DF], RTM_NEWNEIGH, NUD_PROBE}
05-04 14:23:43.862 14619 14619 W         : Unsupported encoding for GPSProcessingMethod
05-04 14:23:43.871 14619 14619 I art     : Starting a blocking GC Alloc
05-04 14:23:43.871 14619 14619 I art     : Starting a blocking GC Alloc
05-04 14:23:43.877 14619 14619 I art     : Alloc sticky concurrent mark sweep GC freed 51(3KB) AllocSpace objects, 1(20KB) LOS objects, 6% free, 108MB/115MB, paused 538us total 5.185ms
05-04 14:23:43.877 14619 14619 I art     : Starting a blocking GC Alloc
05-04 14:23:43.894 14619 14619 I art     : Alloc partial concurrent mark sweep GC freed 20710(1070KB) AllocSpace objects, 0(0B) LOS objects, 13% free, 106MB/122MB, paused 538us total 17.312ms
05-04 14:23:43.894 14619 14619 I art     : Starting a blocking GC Alloc
05-04 14:23:43.925 14619 14619 I art     : Alloc concurrent mark sweep GC freed 8(12KB) AllocSpace objects, 0(0B) LOS objects, 13% free, 106MB/122MB, paused 748us total 28.221ms
05-04 14:23:43.925 14619 14619 I art     : Forcing collection of SoftReferences for 98MB allocation
05-04 14:23:43.925 14619 14619 I art     : Starting a blocking GC Alloc
05-04 14:23:43.950 14619 14619 I art     : Alloc concurrent mark sweep GC freed 5054(241KB) AllocSpace objects, 1(84KB) LOS objects, 13% free, 106MB/122MB, paused 907us total 25.475ms
05-04 14:23:43.951 14619 14619 W art     : Throwing OutOfMemoryError "Failed to allocate a 103711436 byte allocation with 16777216 free bytes and 85MB until OOM"
05-04 14:23:43.952 14619 14619 I art     : Starting a blocking GC Alloc
05-04 14:23:43.952 14619 14619 I art     : Starting a blocking GC Alloc
05-04 14:23:43.957 14619 14619 I art     : Starting a blocking GC Alloc
05-04 14:23:43.971 14619 14619 I art     : Alloc partial concurrent mark sweep GC freed 6(192B) AllocSpace objects, 0(0B) LOS objects, 13% free, 106MB/122MB, paused 542us total 14.274ms
05-04 14:23:43.971 14619 14619 I art     : Starting a blocking GC Alloc
05-04 14:23:43.989 14619 14619 I art     : Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 13% free, 106MB/122MB, paused 580us total 18.081ms
05-04 14:23:43.989 14619 14619 I art     : Forcing collection of SoftReferences for 98MB allocation
05-04 14:23:43.989 14619 14619 I art     : Starting a blocking GC Alloc
05-04 14:23:44.007 14619 14619 I art     : Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 13% free, 106MB/122MB, paused 556us total 17.487ms
05-04 14:23:44.007 14619 14619 W art     : Throwing OutOfMemoryError "Failed to allocate a 103711436 byte allocation with 16776848 free bytes and 85MB until OOM"
05-04 14:23:44.007 14619 14619 D skia    : --- decoder->decode returned false
05-04 14:23:44.008 14619 14619 D AndroidRuntime: Shutting down VM
--------- beginning of crash
05-04 14:23:44.035 14619 14619 E AndroidRuntime: FATAL EXCEPTION: main
05-04 14:23:44.035 14619 14619 E AndroidRuntime: Process: com.wizart, PID: 14619
05-04 14:23:44.035 14619 14619 E AndroidRuntime: java.lang.OutOfMemoryError: Failed to allocate a 103711436 byte allocation with 16776848 free bytes and 85MB until OOM
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:635)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:611)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:391)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:417)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at com.imagepicker.ImagePickerModule.getResizedImage(ImagePickerModule.java:522)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at com.imagepicker.ImagePickerModule.onActivityResult(ImagePickerModule.java:415)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at com.facebook.react.bridge.ReactContext.onActivityResult(ReactContext.java:189)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at com.facebook.react.ReactInstanceManagerImpl.onActivityResult(ReactInstanceManagerImpl.java:596)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at com.facebook.react.ReactActivity.onActivityResult(ReactActivity.java:180)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at android.app.Activity.dispatchActivityResult(Activity.java:6456)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at android.app.ActivityThread.-wrap16(ActivityThread.java)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:102)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:148)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:5417)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
05-04 14:23:44.035 14619 14619 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-04 14:23:44.110   779  1672 W ActivityManager:   Force finishing activity com.wizart/.MainActivity


Most helpful comment

Any idea how to prevent the OutOfMemory error?

Switch to iPhone 馃槀

Just kidding...kind of...(Android's memory management is pretty comical in the year 2016). Duplicate of #155...not really anything we can do about it as far as I know. PRs welcome!

All 2 comments

Try to not resize your image.
Don't set :

maxHeight
Angle
quality

Any idea how to prevent the OutOfMemory error?

Switch to iPhone 馃槀

Just kidding...kind of...(Android's memory management is pretty comical in the year 2016). Duplicate of #155...not really anything we can do about it as far as I know. PRs welcome!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yasserzubair picture yasserzubair  路  3Comments

chai86 picture chai86  路  3Comments

sstur picture sstur  路  4Comments

ozergul picture ozergul  路  3Comments

meurling picture meurling  路  3Comments