Out of memory when switching between screens

I have a problem with my app.

When i jump between 2 screens several times (depending on device memory), then the app crashes with an Out of memory error.

in logcat i get this:
01-09 15:46:11.029 22623 22944 I art : Alloc concurrent mark sweep GC freed 1(32B) AllocSpace objects, 0(0B) LOS objects, 0% free, 79MB/80MB, paused 821us total 62.200ms
01-09 15:46:11.029 22623 22944 W art : Throwing OutOfMemoryError “Failed to allocate a 4000012 byte allocation with 126416 free bytes and 123KB until OOM”
01-09 15:46:11.029 22623 22944 D skia : — decoder->decode returned false
01-09 15:46:11.073 22623 22633 I art : Background sticky concurrent mark sweep GC freed 65(20KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 79MB/80MB, paused 7.716ms total 42.854ms
01-09 15:46:11.079 22623 22944 E AndroidRuntime: FATAL EXCEPTION: Thread-1350
01-09 15:46:11.079 22623 22944 E AndroidRuntime: Process: io.kodular.Launcher_Universal_radio_tv, PID: 22623
01-09 15:46:11.079 22623 22944 E AndroidRuntime: java.lang.OutOfMemoryError: Failed to allocate a 4000012 byte allocation with 126416 free bytes and 123KB until OOM
01-09 15:46:11.079 22623 22944 E AndroidRuntime: at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
01-09 15:46:11.079 22623 22944 E AndroidRuntime: at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
01-09 15:46:11.079 22623 22944 E AndroidRuntime: at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:635)
01-09 15:46:11.079 22623 22944 E AndroidRuntime: at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:611)
01-09 15:46:11.079 22623 22944 E AndroidRuntime: at com.google.appinventor.components.runtime.util.MediaUtil.hxYOFxFjLpN1maJuWNxUV40nExCGxsxkDPOTgtzMu4zlZCQb3bPlKsXo1SYJg6ME(SourceFile:509)
01-09 15:46:11.079 22623 22944 E AndroidRuntime: at com.google.appinventor.components.runtime.util.MediaUtil.B8WBXPBCF2jGfUDZZU2zV5EYdqbUBu0lAZ0THCEqYyuE8VACR9dY7rDnwBIqh64T(SourceFile:42)
01-09 15:46:11.079 22623 22944 E AndroidRuntime: at com.google.appinventor.components.runtime.util.MediaUtil$2.run(SourceFile:456)
01-09 15:46:11.079 22623 22944 E AndroidRuntime: at java.lang.Thread.run(Thread.java:818)
01-09 15:46:11.149 551 3855 I OpenGLRenderer: Initialized EGL, version 1.4

Does anybody know what I have done wrong, or what can cause this error.
When I go form screen2 to screen1, I use Close screen2, simply going to the screen without closing just seems to make it worse.

you have to switch screens correctly, this is the right method for switching between screens,

blocks - 2020-01-10T151149.277

1 Like

It has to do with images, how big are they? Load images when needed and unload when not needed

1 Like

I have tried to decrease image size, and that just postpone the problem.

How can I unload an image?.

I hope you mean decrease in px size, because that’s the most important thing here, so

and how many are loaded at the same time

They are 1000x1000 and about 53k in size.

It loads 3-4 of those on each screen.

(It is on a tablet, not a phone)

Use images as big they need to be.

If tablet is 720x1280px then the images is to big for it, if you use it on a fourth portion of the screen then it is definitely too big for it, etc…