Out of memory, app always crashing


#1

Hi! I have a problem with my application. My app have 3,9mb and only 1 screen. In the middle game when i playing it on my mobile with 4GB RAM my app crashing with error “Out Of Memory”.

I have about 45 images, all is optimized and compressed. How to fix it??


#2

Hard to know if you have your images optimized or not or is it process issue.

Provide some more info about

  • images, sizes in px
  • screen sizing fixed or responsive

by @Italo: 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!).

We can better assist you, the more information we get…

Boban


#3

All my images is 100x60px. I have Fixed screen sizing.
Alll my images are invisible but all is loading at the start.
I want know… What should I do if I want to load only the picture I want to open at this moment?

Sorry for my English!


#4

What do you do to show the images? Do the same, instead of showing or hiding them in that process, set the image file there. That way the image is not using memory while hidden, which doesn’t really makes sense.


#5

Hi! My application always crashing. I’ve tried everything to repair but still crashing… My app have 3,9mb, i have fixed screen sizing.
I have 1 screen, all blocks is okay… I have a lot of canvas & imagesprites, my problem is always full memory, because i have about 50 images and app always crashing in the middle game…
I’ve tried everything to repair but still crashing…

Can you tell me how i can fix this issue, or it is appybuilder bug?

Sorry for my English!

Reports from Google Play:

  1. REPORT

java.lang.OutOfMemoryError:
at dalvik.system.VMRuntime.newNonMovableArray (Native Method)
at android.graphics.Bitmap.nativeCreate (Native Method)
at android.graphics.Bitmap.createBitmap (Bitmap.java:1070)
at android.graphics.Bitmap.createBitmap (Bitmap.java:1040)
at android.graphics.Bitmap.createBitmap (Bitmap.java:944)
at android.graphics.Bitmap.createScaledBitmap (Bitmap.java:820)
at com.google.appinventor.components.runtime.Canvas$CanvasView.onSizeChanged (Canvas.java:436)
at android.view.View.sizeChange (View.java:17806)
at android.view.View.setFrame (View.java:17768)
at android.view.View.layout (View.java:17685)
at android.widget.LinearLayout.setChildFrame (LinearLayout.java:1762)
at android.widget.LinearLayout.layoutVertical (LinearLayout.java:1606)
at android.widget.LinearLayout.onLayout (LinearLayout.java:1515)
at android.view.View.layout (View.java:17688)
at android.view.ViewGroup.layout (ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren (FrameLayout.java:325)
at android.widget.FrameLayout.onLayout (FrameLayout.java:261)
at android.view.View.layout (View.java:17688)
at android.view.ViewGroup.layout (ViewGroup.java:5631)
at com.google.appinventor.components.runtime.ScaledFrameLayout.onLayout (ScaledFrameLayout.java:189)
at android.view.View.layout (View.java:17688)
at android.view.ViewGroup.layout (ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren (FrameLayout.java:325)
at android.widget.FrameLayout.onLayout (FrameLayout.java:261)
at android.view.View.layout (View.java:17688)
at android.view.ViewGroup.layout (ViewGroup.java:5631)
at com.android.internal.widget.ActionBarOverlayLayout.onLayout (ActionBarOverlayLayout.java:493)
at android.view.View.layout (View.java:17688)
at android.view.ViewGroup.layout (ViewGroup.java:5631)
at android.widget.FrameLayout.layoutChildren (FrameLayout.java:325)
at android.widget.FrameLayout.onLayout (FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout (DecorView.java:774)
at android.view.View.layout (View.java:17688)
at android.view.ViewGroup.layout (ViewGroup.java:5631)
at android.view.ViewRootImpl.performLayout (ViewRootImpl.java:2513)
at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2228)
at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1366)
at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:6768)
at android.view.Choreographer$CallbackRecord.run (Choreographer.java:923)
at android.view.Choreographer.doCallbacks (Choreographer.java:735)
at android.view.Choreographer.doFrame (Choreographer.java:667)
at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:909)
at android.os.Handler.handleCallback (Handler.java:761)
at android.os.Handler.dispatchMessage (Handler.java:98)
at android.os.Looper.loop (Looper.java:156)
at android.app.ActivityThread.main (ActivityThread.java:6523)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:941)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:831)

  1. REPORT

java.lang.OutOfMemoryError:
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 com.google.appinventor.components.runtime.util.MediaUtil$3.run (MediaUtil.java:526)
at java.lang.Thread.run (Thread.java:761)

Please HELP!! :frowning:


#6

@TomasVeloso1772 what is your screen orientation set to?


#7

You need drop image size (px) I think its fix your problem.

I do not recommed 50x image for one screen.Its makes memory ıssues


#8

@Ali_Aydin has a :+1: recommendation. If you have multiple screens, make sure you manage opening and closing property.


#11

I have same problem. Thank Ali_Aydin for tip i try it :slight_smile:


#12

Why start a new thread when you have one already with the same issue…:angry::rage:


#13

@Boban_Stojmenovic I just merged the two (I think) and will remove the other one.

@TomasVeloso1772 Please don’t open new threads for same discussion


#14

I don´t know what I can do with this OMG…Today I created 4 next screens, on first screen is 40 images, on 2nd i have 10 images… etc. - all images are optimized (about 100x60px), but app still crashing with error “Out Of Memory” when i want open other screen. Blocks in okay, when i want open another screen old screen was closed…

I need have minimal 40 images on first screen.
And this is a problem. If i open screen all images are invisible but all is loaded at the beggining and all are using a lot of memory.

MY QUESTION: If I want load only 1 image at the moment, how i can do it?


#15

If you set pictures to images or sprites they’ll consume memory, regardless of its visibility


#16

Is it possible to set an Image to “None”?
If i only set my pictures to the components that are visible at the moment and set the invisible components back to None… Does they still use the memory Space from the picture that was load before?


#17

@Guenter if you are not using it, why do you initially assign it a picture?


#18

for example… in my wheel of fortune game i use some buttons in a horizontal arrangement… but during the game i have to show only some of them at the same time… for now i set the picture to them when screen initialize… so they all need memory…

it would be cool to set the buttons to none if they are unvisible to save memory…


#19

Thanks for tip. I will try it tommorow :slight_smile:


#20

Hi,

I don’t know if this Thread still exist but I have a problem. I made a app using AppyBuilder and It has total of more than 4 screens and I have to switch screen more often. I would need to take users to different pages and at some points the app crashed due to Out of memory error. I have got the report from Google play and I have uploaded the image.

I want a solution to fix this as soon ad possible because I am getting request from my Users


#21

Same problem here. Has anyone solved it? I am downloading images from firebase , it displays fine but suddenly this error appears.


#22

@K_L It Out of Memory, depends on number and size of images. Dos your app handle lots of images?