Javi Teje
Javi Teje

Reputation: 66

Memory management with background service

I created an application that creates a background service. When I close the application the service is running and when I go back to get it back to "bind" (bindService) to it for communications.

The problem is that when I close the application and re-enter, it significantly increases the memory in use. Spend 20Mb -> 24Mb, if I go out and come 24Mb -> 28Mb, 28Mb -> 30Mb ... Thus breaking up the application. I have no bitmaps. That if enough use static arrays but I've tested and are not the source of the problem.

When I close the application completely (including service) call System.exit(0) and clean all the memory, but of course, I can call when I leave the service running as it closes. I tried to call the Garbage Collector (System.gc()) and if I notice that memory decreases to close, but when you open the application again same memory increases.

I would greatly appreciate the help, Bye!

Upvotes: 0

Views: 793

Answers (1)

AlexN
AlexN

Reputation: 2554

Considering information we have, I suspect the problem is an Activity leak. Can you please check 2 things:

  1. Check carefully do you use Activity Context (reference to Activity) that can be stored? Particularly in Service.
  2. Try to make an experiment - select "Do not keep activities" in Developer setting - will the memory be decreasing after each Activity launch?

Upvotes: 1

Related Questions