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

Crash due to out of memory error which trying to compress image using createResizedImage #97

Closed
bdipak opened this Issue Aug 9, 2017 · 4 comments

Comments

Projects
None yet
5 participants
@bdipak

bdipak commented Aug 9, 2017

While trying to resize large image of size around 5MB, there is an out of memory exception on some lower end phones with low memory. Out of memory exception in this case is expected but it should be gracefully handled instead of crashing the application.

Shouldn't it try to catch all such out of memory exceptions and throw resize error exception to caller? Since it is crashing my app, I am not able to use it in our production app. Please see if you can consider this.

@4ian

This comment has been minimized.

Show comment
Hide comment
@4ian

4ian Aug 12, 2017

Collaborator

Such exception should indeed be catched and reported properly. If anyone is able to do it, I'll merge the PR so that the next version is protected against this.

Collaborator

4ian commented Aug 12, 2017

Such exception should indeed be catched and reported properly. If anyone is able to do it, I'll merge the PR so that the next version is protected against this.

@freiserg

This comment has been minimized.

Show comment
Hide comment
@freiserg

freiserg Aug 26, 2017

Contributor

@4ian StackTrace such crach:

java.lang.OutOfMemoryError: Failed to allocate a 2430012 byte allocation with 1305354 free bytes and 1274KB until OOM
    at dalvik.system.VMRuntime.newNonMovableArray(VMRuntime.java)
    at android.graphics.Bitmap.nativeCreate(Bitmap.java)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:946)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:917)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:848)
    at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:724)
    at fr.bamlab.rnimageresizer.ImageResizer.resizeImage(ImageResizer.java:53)
    at fr.bamlab.rnimageresizer.ImageResizer.createResizedImage(ImageResizer.java:283)
    at fr.bamlab.rnimageresizer.ImageResizerModule.createResizedImageWithExceptions(ImageResizerModule.java:52)
    at fr.bamlab.rnimageresizer.ImageResizerModule.createResizedImage(ImageResizerModule.java:37)

It try to catch only IOException exceptions link to code

Shouldn't it try to catch all exceptions?

Contributor

freiserg commented Aug 26, 2017

@4ian StackTrace such crach:

java.lang.OutOfMemoryError: Failed to allocate a 2430012 byte allocation with 1305354 free bytes and 1274KB until OOM
    at dalvik.system.VMRuntime.newNonMovableArray(VMRuntime.java)
    at android.graphics.Bitmap.nativeCreate(Bitmap.java)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:946)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:917)
    at android.graphics.Bitmap.createBitmap(Bitmap.java:848)
    at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:724)
    at fr.bamlab.rnimageresizer.ImageResizer.resizeImage(ImageResizer.java:53)
    at fr.bamlab.rnimageresizer.ImageResizer.createResizedImage(ImageResizer.java:283)
    at fr.bamlab.rnimageresizer.ImageResizerModule.createResizedImageWithExceptions(ImageResizerModule.java:52)
    at fr.bamlab.rnimageresizer.ImageResizerModule.createResizedImage(ImageResizerModule.java:37)

It try to catch only IOException exceptions link to code

Shouldn't it try to catch all exceptions?

@holyxiaoxin

This comment has been minimized.

Show comment
Hide comment
@holyxiaoxin

holyxiaoxin Sep 1, 2017

And also, to add on, you can increase your memory heap by setting:
android:largeHeap="true" in manifest file:

https://stackoverflow.com/questions/32244851/androidjava-lang-outofmemoryerror-failed-to-allocate-a-23970828-byte-allocatio

This reduces the chance of having OOM error thrown when dealing with large bitmaps.

holyxiaoxin commented Sep 1, 2017

And also, to add on, you can increase your memory heap by setting:
android:largeHeap="true" in manifest file:

https://stackoverflow.com/questions/32244851/androidjava-lang-outofmemoryerror-failed-to-allocate-a-23970828-byte-allocatio

This reduces the chance of having OOM error thrown when dealing with large bitmaps.

@viju85

This comment has been minimized.

Show comment
Hide comment
@viju85

viju85 Sep 1, 2017

I am seeing the same crash with below stacktrace:
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 110806760 byte allocation with 33554432 free bytes and 37MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.Bitmap.nativeCreate(Native Method) at android.graphics.Bitmap.createBitmap(Bitmap.java:879) at android.graphics.Bitmap.createBitmap(Bitmap.java:856) at android.graphics.Bitmap.createBitmap(Bitmap.java:787) at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:663) at fr.bamlab.rnimageresizer.a.a(SourceFile:2048) at fr.bamlab.rnimageresizer.ImageResizerModule.createResizedImageWithExceptions(SourceFile:54) at fr.bamlab.rnimageresizer.ImageResizerModule.createResizedImage(SourceFile:41)

viju85 commented Sep 1, 2017

I am seeing the same crash with below stacktrace:
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 110806760 byte allocation with 33554432 free bytes and 37MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.Bitmap.nativeCreate(Native Method) at android.graphics.Bitmap.createBitmap(Bitmap.java:879) at android.graphics.Bitmap.createBitmap(Bitmap.java:856) at android.graphics.Bitmap.createBitmap(Bitmap.java:787) at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:663) at fr.bamlab.rnimageresizer.a.a(SourceFile:2048) at fr.bamlab.rnimageresizer.ImageResizerModule.createResizedImageWithExceptions(SourceFile:54) at fr.bamlab.rnimageresizer.ImageResizerModule.createResizedImage(SourceFile:41)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment