Android Question Crash after Days - do i have a Memory-Problem?

Licht2002

Member
Licensed User
Longtime User
Hello to All,

I have an ACER Smartdisplay 24”!

20972132fa.jpg


in B4A I wrote an app with:

Webcam-Slideshow (Picasso-Lib - LoadintoBitmap)

Wheather Forecast in a Webview

Download Stockquote and parsing them

Webradio

CCTV-Wifi-Webcam (with Picasso-Lib - Target1) on UDP-Event from a PIR-Sensor connected to an Arduino/Ethernetshield

Monitoring temperature (Inside, Outside and Heating/Warmwater)

Monitoring electric meter

RF433-Remote-Socket (USB to Arduino mit RF-433 Transmitter)

HTTP-Server (Private Homepage with Montitoring-Data)

FTP object for load config-files and logging

UDP-Socket (Push/Pull Data from Arduino / Smartphone)


My problem – the app crashes after 1 or 2 days….. first i add to all subs a "Try-Catch".... crash again

So i add a Sub GetFreeMem:

B4X:
Sub GetFreeMem As Int
   Dim r As Reflector
   Dim MM, TM, FM, Total As Int
   r.Target = r.RunStaticMethod("java.lang.Runtime", "getRuntime", Null, Null)
   MM = r.RunMethod("maxMemory")
   FM = r.RunMethod("freeMemory")
   TM = r.RunMethod("totalMemory")
   Total = MM + FM - TM - r.RunStaticMethod("android.os.Debug", "getNativeHeapAllocatedSize", Null, Null)
   Return Total / 1024000

End Sub


Now i see.... my Memory shrinks:

Minutes after Start: 20150212-110137: GetFreemMem MB: 384


6 hours later: 20150212-173045: GetFreemMem MB: 296

The GC do not change so much:
From: GC_CONCURRENT freed 397K, 33% free 3027K/4468K, paused 3ms+2ms, total 32ms
TO: GC_CONCURRENT freed 384K, 33% free 3027K/4468K, paused 2ms+1ms, total 24ms

Can this be a/the Problem?

Thx Tom

PS1: I use only 4 Bitmap - with max 1920x1080 (after use -> = null)
PS2: The Code is about 120 kb with some IP/Password inside... so i do not want to post the code completly in the forum
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
Have you tried to compare your app behaviour with a task manager/killer installed and setup to free ram every hour?
 
Upvote 0

Licht2002

Member
Licensed User
Longtime User
[QUOTE="compare your app behaviour with a task manager/killer installed and setup to free ram every hour?[/QUOTE]

Thanks for your reply,

do you meam the Taskmanager on the tablet?

20976596rk.jpg

How can i "setup to free ram".... do you have a link for me?

Thank you!!!

Tom
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I use "advanced task manager" from the PSTORE. It's quite useful. .. I have my phone cleaning both when screen off and every 15min
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The UI Cloud devices (10 devices) run a special version of B4A-Designer and they run for months.

Running an app for a long time is difficult. The solution I chose is to use two apps. The main app and a secondary app that is responsible for keeping the other app running.

Let the main app kill (ExitApplication) itself every couple of hours. The secondary app should use a foreground service and use StartServiceAt to make sure that it is running all the time.

The secondary app should start the main app with StartActivity every minute. If the main app is already running, nothing will happen (Activity_Resume will be called). If it is not running it will be started.
 
Upvote 0

Licht2002

Member
Licensed User
Longtime User
Running an app for a long time is difficult. The solution I chose is to use two apps.

Hi Erel,

thanks for your Tip, but when my tablet crashes - it is bricked.

I have to remove the power-adapter (the Tablet has no battery - only main-voltage).

At the moment, the app runs for nearly 24h without crash.


Now i have 206 MB free.... says GetFreeMem
20150213-095010: GetFreemMem MB: 206


20977333ph.png
20977334up.jpg




I have to wait - until crash

Thx

Tom
 
Upvote 0

eps

Expert
Licensed User
Longtime User
I would check the memory usage after a few hours and see if the App is consuming more and more.

I'd also take a look to ensure that Bitmaps are defined globally and not being re-dimmed, but I'm sure it would crash way before that.

You could get the App to email you the log(s) every hour or so and inform you of memory usage, etc... as opposed to just waiting for it to crash.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Hi Erel,

thanks for your Tip, but when my tablet crashes - it is bricked.

I have to remove the power-adapter (the Tablet has no battery - only main-voltage).

At the moment, the app runs for nearly 24h without crash.


Now i have 206 MB free.... says GetFreeMem
20150213-095010: GetFreemMem MB: 206


20977333ph.png
20977334up.jpg




I have to wait - until crash

Thx

Tom
Have you set the Adv.Task Man. To automatically free memory? (Auto Kill Frequency )
 
Upvote 0

Licht2002

Member
Licensed User
Longtime User
Have you set the Adv.Task Man. To automatically free memory? (Auto Kill Frequency )

Yes i did.... with 15min Autokill!

My needed MEM rised in last 3 hour from 212MB to 240MB

and the free MEM shrinks from

20150213-095010: GetFreemMem MB: 206
to
20150213-124047: GetFreemMem MB: 177

I still waiting for the crash ;-(

Thx
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
The secondary app should start the main app with StartActivity every minute. If the main app is already running, nothing will happen (Activity_Resume will be called). If it is not running it will be started.

This is a great solution @Erel, I will have to remember this or just make a note a note of it for future reference.

Cheers :cool:
 
Upvote 0
Top