OutOfMemoryError to Save Image

I am uploading the image from my library and using it in SfImageEditor.
But when I try to save a memory out of memory error.

[art] Starting a blocking GC Alloc
[art] Starting a blocking GC Alloc
[art] Starting a blocking GC Alloc
[art] Clamp target GC heap from 135MB to 128MB
[art] Alloc partial concurrent mark sweep GC freed 16(560B) AllocSpace objects, 1(7MB) LOS objects, 6% free, 119MB/128MB, paused 306us total 9.359ms
[art] Starting a blocking GC Alloc
[art] Starting a blocking GC Alloc
[art] Alloc sticky concurrent mark sweep GC freed 27(864B) AllocSpace objects, 0(0B) LOS objects, 0% free, 126MB/128MB, paused 421us total 6.645ms
[art] Starting a blocking GC Alloc
[art] Clamp target GC heap from 142MB to 128MB
[art] Alloc partial concurrent mark sweep GC freed 8(256B) AllocSpace objects, 0(0B) LOS objects, 0% free, 126MB/128MB, paused 432us total 12.508ms
[art] Starting a blocking GC Alloc
[art] Clamp target GC heap from 142MB to 128MB
[art] Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 0% free, 126MB/128MB, paused 432us total 17.858ms
[art] Forcing collection of SoftReferences for 2MB allocation
[art] Starting a blocking GC Alloc
[art] Clamp target GC heap from 142MB to 128MB
[art] Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 0% free, 126MB/128MB, paused 433us total 19.738ms
[art] Throwing OutOfMemoryError "Failed to allocate a 2378544 byte allocation with 1105168 free bytes and 1079KB until OOM"
[art] Starting a blocking GC Alloc
[art] Starting a blocking GC Alloc
[art] Alloc sticky concurrent mark sweep GC freed 3(400B) AllocSpace objects, 0(0B) LOS objects, 0% free, 126MB/128MB, paused 407us total 5.098ms
[art] Starting a blocking GC Alloc
[art] Clamp target GC heap from 142MB to 128MB
[art] Alloc partial concurrent mark sweep GC freed 6(192B) AllocSpace objects, 0(0B) LOS objects, 0% free, 126MB/128MB, paused 427us total 12.187ms
[art] Starting a blocking GC Alloc
[art] Clamp target GC heap from 142MB to 128MB
[art] Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 0% free, 126MB/128MB, paused 380us total 17.039ms
[art] Forcing collection of SoftReferences for 2MB allocation
[art] Starting a blocking GC Alloc
[art] Clamp target GC heap from 142MB to 128MB
[art] Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 0% free, 126MB/128MB, paused 348us total 15.209ms
[art] Throwing OutOfMemoryError "Failed to allocate a 2378544 byte allocation with 1105168 free bytes and 1079KB until OOM"

5 Replies

MV Mohana V Syncfusion Team March 26, 2018 12:37 PM UTC

Hi Rudá,

Sorry for the inconvenience caused.

We have validated the reported issue based on the stack trace. We are unable to reproduce the reproted issue while loading image to the image editor and please find the sample for the same from the below link,

http://www.syncfusion.com/downloads/support/directtrac/general/ze/sample1-2107267660 

We suspect that the reason for this exception is depends on the application size. When you are including the SfImage Editor in your application, it needs some memory to process the image. If your application is already insufficient to allocate the space, then we will not able to load the image. For example, If you want to edit 4 MB image file and your application remaining memory is 2MB then there is no space to load the image since we are rendering the image as Bitmap in Android.

So, could you please share us the image size that you are trying to load to the image editor and the exact scenario when you are facing this issue, so that we would assist you further from our side.

Regards,
Mohana V 



CH Christian December 10, 2019 12:11 PM UTC

Hi,

I have the same problem getting an OutOfMemoryException if the image is too big. The problem for me is that I can't catch this exception and the app just crashes. If you use your sample project with the image I attach to this post I get this log in the output window when the app crashes:
12-10 12:54:42.401 W/art     (15474): Throwing OutOfMemoryError "Failed to allocate a 71568012 byte allocation with 16777216 free bytes and 39MB until OOM"

When I use the recommendation with "android:largeHeap="true"" to prevent this like it is described in your article from https://www.syncfusion.com/kb/8301/how-to-resolve-out-of-memory-exception-when-loading-large-images-in-android I get this output and the app crashes with the following output:
12-10 12:31:38.731 W/OpenGLRenderer(14313): Bitmap too large to be uploaded into a texture (4000x4473, max=4096x4096)

I don't realy want to set this option. Only a possibility to catch the exception if something went wrong would be enoug to inform the user that the image is too big instead of app crash.

Some additional info:
  • It only crashes on Android, not iOS.

  • The file size of the image is "only" around 2.794.496 bytes. The OutOfMemoryException is saying 71.568.012  bytes which is a lot more. I think the problem is that the file size is the compressed jpg size and when it loaded its the full uncompressed bitmap size of 4000 width x 4473 height x 4 RGBA = 71568000 which matches the info from the exception quite well.
I use your editor only to let the user crop the image so it's not a good option for me to downsize the image BEFORE (which works with the MediaPlugin after the user selected the image for example (https://github.com/jamesmontemagno/MediaPlugin)) because then I loose a lot of resolution for the image which will make no sense if the image is quite smaller after the cropping.

So an option to prevent the app crash and inform the user about that would be enough but how?

Kind regards
Chris

Attachment: Image_1fe1c75b.zip


RA Rachel A Syncfusion Team December 11, 2019 01:12 PM UTC

Hi Christian, 
 
We have prepared SfImageEditor sample and checked the reported crash by loading the provided image. But we afraid that, we are not able to reproduce the reported crash in our side. Can you please check with the tested sample in the following location? 
 
 
If still you are facing the problem, please revert us by modifying the sample based on your application along with replication steps, device configurations, etc. This would be helpful for us to give better solution in this. 
 
We have checked with the below configuration 
 
Android: 
VS: Professional 2019, Version: 16.3.3 
Device: Moto E2 with API 23 
Simulator: Nexus 10 with API 9.0 
Syncfusion Version: 17.3.0.34 
 
Also, can you please crosscheck whether there is available space in memory for deploying the app. 
 
Regards,
Rachel.
 



CH Christian December 12, 2019 11:52 AM UTC

Thanks for checking.

I tried the original sample with a real (but old) device (Samsung SM-G800F, Android 6.0 - API 23). On this device your new sample works. The orignal sample from this thread is quite old and you are using the newest Syncfusion release in the new one so I thought maybe the problem is solved, but after I enlarged the image (I doubled the size) I ran into a problem again:

12-12 11:49:22.958 W/art     ( 9612): Throwing OutOfMemoryError "Failed to allocate a 71568012 byte allocation with 16766416 free bytes and 53MB until OOM"
12-12 11:49:22.998 W/OpenGLRenderer( 9612): Bitmap too large to be uploaded into a texture (4000x4473, max=4096x4096)

And if I try your sample with the same image like in your sample on a Sony E5823, Android 7.1 - API 25 I directly run into the OutOfMemoryExcpetion again:

12-12 12:42:12.787 W/art     (15471): Throwing OutOfMemoryError "Failed to allocate a 71568012 byte allocation with 16777216 free bytes and 51MB until OOM"

With an Nexus emulator with API 9 I couldn't reproduce this behaviour even if I set the memory of the emulator quite low (64MB).


Hm, but anyway...
Is there a possibility to catch an Exception which happens inside the SFImageEditor so the app don't crash and I can just inform the user that the selected image is to large, not valid or whatever?
I tried it with a try/except around the assignment to the Source property, but no success.








RA Rachel A Syncfusion Team December 13, 2019 01:42 PM UTC

Hi Christian, 
 
While converting large image to bitmap using CreateBitMap() method, it throws out of memory exception in framework itself. So, we are unable to catch in our source. 
 
[C#]: 
Bitmap.CreateBitmap(width, height, config); 
 
To overcome this issue, we suggest you use compressed image 
 
Regards, 
Rachel. 


Loader.
Up arrow icon