B4A app memory footprint or what happens with my app memory?

bsnqt

Active Member
Licensed User
Longtime User
Hi Erel,

I am working on an sms interceptor app. I observed and see that my app is running using 18 - 20Mb of memory, which is too high comparing with other softwares (in my phone, normally they are using min 4 - max 10Mb in average). After a while, I discovered that my Service (sms interceptor) is "eating" a lot of memory.

To confirm which part in my app is causing high memory "consumption", I make a simplest test project (please see attached) with a Service. Amazingly, this single and simple service is running at a very high memory consumption 10Mb - 11Mb (we can see that in the Running Service / Settings).

1) Is it normal that such app is "eating" 10Mb in B4A? It is actually a very simple project, my real app is much more complicated and is expected to consume much more memory...and which is not acceptable for me (I believe 4 - 5Mb is ok?)

2) How can I reduce the memory footprint of my running app?

Thank you very much.

Regards,
 

Attachments

  • TestService(1).zip
    6.4 KB · Views: 227
Last edited:

bsnqt

Active Member
Licensed User
Longtime User
Your sample uses 6.5MBb on my Android 4.1.2 Xoom which looks about the same as other simple demo programs that write. If I kill the Activity the service remains running and uses 2.9MB. By comparison B4A-bridge uses 7.8MB

Hi agraham

Thank you for your comment.

It s really strange, same demo app is consuming 9.8 - 10Mb on my device and I re-run many times to check... and I can confirm. I am using SONY EXPERIA S. Please see attached.
 

Attachments

  • Screenshot.zip
    146.6 KB · Views: 257
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
Basic4android doesn't add any extra layer for your application. You can check the generated Java source files.

Hi Erel,

Yes I fully understand, that is why I have to spend almost 2 - 3 days to observe what happens with my Service... I cannot explain.

Why do you call StartServiceAt every 3 seconds?

I don't want the System kill my Service and achieve the same result as when I use Service.StartForeground(1,n1). However, with StartForeground the chance my Service get killed is very high.

Actually I do make another test project with Service.StartForeground(1,n1) and it does give same memory consumption, i.e. 10Mb. Please see attached.

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim SI As SmsInterceptor
   Dim n1 As Notification
End Sub
Sub Service_Create
   SI.Initialize2("SI", 2147483647)
   n1.Initialize
   n1.Sound = False   
   n1.Vibrate = False
   n1.Icon = "icon"
   n1.SetInfo("This is my app", "Test", Main)   
   n1.AutoCancel= True
   n1.OnGoingEvent = True
   n1.Notify(1)
End Sub

Sub Service_Start (StartingIntent As Intent)
   Service.StartForeground(1,n1)
'   StartServiceAt("", DateTime.Now + 3000, True)
End Sub

Sub Service_Destroy

End Sub

Sub SI_MessageReceived (From As String, Contents As String) As Boolean
   Log("From: " & From & ", Contents: " & Contents)
   Return False
End Sub
 

Attachments

  • TestService(2).zip
    6.6 KB · Views: 226
Upvote 0
Top