cloudinary/cloudinary_android

Fatal Exception: java.lang.OutOfMemoryError

shubhendu1 opened this issue · 9 comments

Fatal Exception: java.lang.OutOfMemoryError
Failed to allocate a 47 byte allocation with 0 free bytes and 3GB until OOM

com.cloudinary.android.preprocess.Limit.execute (Limit.java:44)
com.cloudinary.android.preprocess.Limit.execute (Limit.java:12)
com.cloudinary.android.preprocess.PreprocessChain.execute (PreprocessChain.java:76)
com.cloudinary.android.UploadRequest.preprocessAndClone (UploadRequest.java:268)
com.cloudinary.android.UploadRequest.access$100 (UploadRequest.java:32)
com.cloudinary.android.UploadRequest$1.run (UploadRequest.java:213)

Hi @shubhendu1 ,

In order to better understand the issue, I need some more information. Can you please share with me the following?

  • Cloudinary SDK version
  • The image you worked with
  • Android OS version
  • Full error stack trace.

Looking forward to your response.

Best,
Yakir

Hello @yakirp
These are the details that I can provide, as this is the crash that one of our user encountered and details provided here are from Crashlytics.

  • Cloudinary SDK version
    1.25.0

  • Android OS version
    7.1.1
    Device - Moto E (4)

  • Full error stack trace

Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 47 byte allocation with 0 free bytes and 3GB until OOM
       at android.graphics.Bitmap.nativeCreate(Bitmap.java)
       at android.graphics.Bitmap.createBitmap(Bitmap.java:905)
       at android.graphics.Bitmap.createBitmap(Bitmap.java:882)
       at android.graphics.Bitmap.createBitmap(Bitmap.java:813)
       at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:689)
       at com.cloudinary.android.preprocess.Limit.execute(Limit.java:44)
       at com.cloudinary.android.preprocess.Limit.execute(Limit.java:12)
       at com.cloudinary.android.preprocess.PreprocessChain.execute(PreprocessChain.java:76)
       at com.cloudinary.android.UploadRequest.preprocessAndClone(UploadRequest.java:268)
       at com.cloudinary.android.UploadRequest.access$100(UploadRequest.java:32)
       at com.cloudinary.android.UploadRequest$1.run(UploadRequest.java:213)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
       at java.lang.Thread.run(Thread.java:761)

And one more thing I wanted bring into your knowledge that, in one of our activities we are using Cloudinary upload inside of a for loop for multiple uploads. And also, we are using startNow() instead of dispatch() for immediate upload request.

Thanks,
Shubhendu

Thanks for this information.

Looks that you are using both preprocess and for loop, so it definitely could cause such issue like out of memory.

You need to check that you are not sending too many images with preprocess or to use dispatch()

Please let me know if it works for you.

Best
Yakir

Maximum of 10 images are allowed at once, but we do not have any control over the size of the image.

So, in that case, is there any other way possible for us to upload multiple images at once.

And if possible can you please suggest the correct way of implementing multiple image upload logic.

Thanks,
Shubhendu

10 mages could easily cause this issue.
Please try to use dispatch() - This will handle the preprocess and the upload with mange queue.

Please let me know if it works for you.

Best
Yakir

As I understand dispatch() utilises JobScheduler and might take some time to start the upload process.

My requirement is to start the upload as soon as user clicks.

So, there are two major requirement that I have to fulfill

  • Multiple Image upload (Max 10 at a time)

  • Upload process should start immediately.

Thanks,
Shubhendu

Hi @shubhendu1

I think that the best option is the dispatch() because you must manage this heavy process. So it's up to you if to manage that with our queue which is baes on Google best practices for Android, or to find another to manage such a process.

Please let me know what you think

Cheers,
Yakir

Hi @shubhendu1

I'm following up to see whether you had a chance to look into my response?
Please let me know if you have questions?

Thanks,
Yakir

Hi @yakirp

Sorry for the delay.
I have not implemented your solution but have not got similar crash again, so I think that might be an edge case. If problem occurs again, will surely check your solution.

Thank you,
Shubhendu