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

Discussion in 'Android Questions' started by Licht2002, Feb 12, 2015.

  1. Licht2002

    Licht2002 Member Licensed User

    Hello to All,

    I have an ACER Smartdisplay 24”!

    [​IMG]

    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:

    Code:
    Sub GetFreeMem As Int
       
    Dim r As Reflector
       
    Dim MM, TM, FM, Total As Int
       r.Target = r.RunStaticMethod(
    "java.lang.Runtime""getRuntime"NullNull)
       MM = r.RunMethod(
    "maxMemory")
       FM = r.RunMethod(
    "freeMemory")
       TM = r.RunMethod(
    "totalMemory")
       Total = MM + FM - TM - r.RunStaticMethod(
    "android.os.Debug""getNativeHeapAllocatedSize"NullNull)
       
    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: Feb 12, 2015
  2. KMatle

    KMatle Expert Licensed User

  3. Cableguy

    Cableguy Expert Licensed User

    Have you tried to compare your app behaviour with a task manager/killer installed and setup to free ram every hour?
     
  4. Licht2002

    Licht2002 Member Licensed 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?

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

    Thank you!!!

    Tom
     
  5. Cableguy

    Cableguy Expert Licensed 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
     
    Rob Rendle likes this.
  6. Erel

    Erel Administrator Staff Member Licensed 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.
     
    Peter Simpson, eps and Cableguy like this.
  7. Licht2002

    Licht2002 Member Licensed 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


    [​IMG] [​IMG]



    I have to wait - until crash

    Thx

    Tom
     
  8. eps

    eps Well-Known Member Licensed 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.
     
  9. Cableguy

    Cableguy Expert Licensed User

    Have you set the Adv.Task Man. To automatically free memory? (Auto Kill Frequency )
     
  10. Licht2002

    Licht2002 Member Licensed User

    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
     
    Cableguy likes this.
  11. Peter Simpson

    Peter Simpson Expert Licensed User

    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:
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice