App crashes (out of Memory)


#1

Hy

I use the Barcodescanner to scan a QR-Code. However after several scans the App does crash.
When I use ADB with logcat I get this error where I can see that the app did run out of memory:
How can I prevent this from happening?


#2

How many screen do you use ?


#3

I use one main screen where you have a button to go to another screen. there a popup apears to inform you that you need now to scan the qr-code. after touching ok the scanner starts you scan the QR code and the screen gets closed back to the main screen (the infos about the qr code are posted to a php webpage before closing the screen)


#4

Do you sue this ?
https://puravidaapps.com/tribblehunter.php


#5

for this test no because I open the new screen and I let the main screen running in the background.
after the scan is finished this screen gets closed and the main screen will be visible again


#6

when you close the 2nd screen, use this method, it may help!
Why keep the main screen open?


#7

ok I just tested this method (I know it from other apps I made) however the app still crashes after 10 to 15 scans even with this method


#8

Sorry no other idea…


#9

do you display several large images inside the app?
see also tip 2 here


Taifun


#10

hmm the largest Image is 7Kb i don’t think this is “large”…


#11

by @Italo taken from here https://groups.google.com/d/msg/mitappinventortest/5kVipjP0jdI/V13FcGeNBAAJ
also how many images altogether are you displaying on that screen?
Taifun

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!).


#12

a maximum of five images at the same time. And two images are invisible in the background and are only visible when the other fours are invisibel
On the second screen there are no images

(do the images also take up memory space when they are not visible?)


#13

you might want to read my previous answer again to find the answer to this question
Taifun


#14

ok sorry I missed that point.
So can we check within the app how much memory is available?


#15

when we close a screen will the used memory by this screen be free again to be used by another screen etc?


#16

yes, see also The recommended method of switching screens in App Inventor
Taifun


#17

hmm strange my app runs still out of memory even when the screen is properly closed…
Is there no way to get the memory left back in an app?


#18

Upload your aia and let’s see what’s wrong with it.