App crashes (out of Memory)



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?


How many screen do you use ?


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)


Do you sue this ?


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


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


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


Sorry no other idea…


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



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


by @Italo taken from here
also how many images altogether are you displaying on that screen?

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


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?)


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


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


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


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


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?


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