react-native-image-resizer
react-native-image-resizer copied to clipboard
Thoughts on gracefully handling OOM (Android)?
Not really critical, but some bad android devices may crash from time to time when loading the image into memory. Example:
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 20155404 byte allocation with 16777216 free bytes and 16MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(VMRuntime.java:-2)
at android.graphics.BitmapFactory.nativeDecodeStream(BitmapFactory.java:-2)
at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:853)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:829)
at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:487)
at fr.bamlab.rnimageresizer.ImageResizer.loadBitmap(ImageResizer.java:384)
at fr.bamlab.rnimageresizer.ImageResizer.loadBitmapFromFile(ImageResizer.java:414)
at fr.bamlab.rnimageresizer.ImageResizer.createResizedImage(ImageResizer.java:529)
at fr.bamlab.rnimageresizer.ImageResizerModule.createResizedImageWithExceptions(ImageResizerModule.java:81)
at fr.bamlab.rnimageresizer.ImageResizerModule.access$000(ImageResizerModule.java:27)
at fr.bamlab.rnimageresizer.ImageResizerModule$1.doInBackgroundGuarded(ImageResizerModule.java:63)
at fr.bamlab.rnimageresizer.ImageResizerModule$1.doInBackgroundGuarded(ImageResizerModule.java:59)
at com.facebook.react.bridge.GuardedAsyncTask.doInBackground(GuardedAsyncTask.java:36)
at com.facebook.react.bridge.GuardedAsyncTask.doInBackground(GuardedAsyncTask.java:20)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
I wonder if it would be worth it handling this error more gracefully.
Same issue here. The Crashlytics log says that the device has more than 800MB of RAM free but the crash only 2MB until OOM.
ImageResizer.java line 198
fr.bamlab.rnimageresizer.ImageResizer.saveImage
Caused by java.lang.OutOfMemoryError
Failed to allocate a 4194316 byte allocation with 3119088 free bytes and 2MB until OOM
fr.bamlab.rnimageresizer.ImageResizer.saveImage
Hello, Wondering what should be the expected behavior in that scenario. Probably returning an error with an error code relative to an OOM issue.
I gave up entirely on relying on devices to resize images. You will encounter poor devices that go OOM. I do all my resizing on the server now. If you're getting picture from the camera, then I recommend looking into requesting a smaller resolution photo from the camera.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically closed. Thank you for your contributions.