Throwing OutOfMemoryError


#1

Hi my application also have 6 screens. When I change the screen more than once in the application, I get the error that an application has stopped. I have run ADB Logcat and I have recorded the records as follows, how can I fix this error?
(I have many blocks in the application so I can’t share the screenshot.)

3876 6001 I art : Forcing collection of SoftReferences for 4MB allocation
3876 6001 I art : Starting a blocking GC Alloc
3876 6001 I art : Clamp target GC heap from 139MB to 128MB
3876 6001 I art : Alloc concurrent mark sweep GC freed 3(72B) AllocSpace objects, 0(0B) LOS objects, 3% free, 123MB/128MB, paused 2.590ms total 88.259ms
3876 6001 W art : Throwing OutOfMemoryError "Failed to allocate a 5172812 byte allocation tes and 4MB until OOM"
3876 6001 E AndroidRuntime: FATAL EXCEPTION: Thread-97
3876 6001 E AndroidRuntime: Process: com.xxxxxxx, PID: 3876
3876 6001 E AndroidRuntime: java.lang.OutOfMemoryError: Failed to allocate a 5172812 byte allocation with 4891184 free bytes and 4MB until OOM
3876 6001 E AndroidRuntime: at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
3876 6001 E AndroidRuntime: at android.graphics.Bitmap.nativeCreate(Native Method)
3876 6001 E AndroidRuntime: at android.graphics.Bitmap.createBitmap(Bitmap.java:879)
3876 6001 E AndroidRuntime: at android.graphics.Bitmap.createBitmap(Bitmap.java:856)
3876 6001 E AndroidRuntime: at android.graphics.Bitmap.createBitmap(Bitmap.java:787)
3876 6001 E AndroidRuntime: at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:663)
3876 6001 E AndroidRuntime: at com.google.appinventor.components.runtime.util.MediaUtil$2.run(MediaUtil.java:514)


#2

Try this:
https://puravidaapps.com/tribblehunter.php


#3

see tip 1 and 2


Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.


#4

You need to properly handle changing screens

CC @Taifun


#5

@Taifun @Ken
Screenshot_2

I’m already using this method. I will try to change the size of the picture, thank you.


#6

Hello,

I have a question about this topic.
I try to follow all Tips and Tricks from Taifun.

There is a quote from Italo

I do not know if I understand correctly.
I use also arrangements as “screens”, there is one screen, invisible at initialized, that contains many images.

Is it now better not to set pictures but only when it becomes visible?
OnClick
Arrangement visible
Set image to…

Or do I misunderstand this?

Kind regards
Thomas


#7

By the great @italo :sunglasses:

First, you need to understand that the file size of an image is not the amount of memory it uses when it’s being displayed. The file size is the compressed size, much like a zip or rar file. When viewed, the image needs to be decompressed.
For example, if your image says its file size is 100 kb, and its dimensions are 1024 x 768, 32 bit color, then that image uses over 3 mb of RAM (not 100 kb!) when you show it on the screen. ((1024 * 768 ) * 32) / 8 = 3,145,728 kb (3 mb)
Now, this is a mistake most people make when using arrangements as “virtual screens”: They set different image components with their images loaded but hidden, instead of having only one image component and changing the picture according to the user’s selection or app events, not knowing that apparently the hidden image components are also using the ram, (yes, even though they are invisible!).


#8

Hello Peter,
Thanks for your response.
Yes, I know that and I try to pay attention. :wink:

My question is aiming for something else.
Is it better to set images inside arrangements inside the block editor only when the arrangement becomes visible or make it no difference…

Thomas


#9

Here is your answer. It was in the quote from Italo.