I have an app with a foreground service and one activity. The service can either start on its own on boot, or be started from within the activity. I have noticed when the service starts itself on boot, the memory usage is ~3mB. Once I open the activity, memory usage jumps up to about ~9mB. Once the activity has been opened (and then closed either by back or home button), the memory never drops back down to 3mB, even after many hours and other apps opening.
My question is, should the memory from the activity be released or is this expected with a foreground service?
It turns out Android will not release the activity from memory until the entire process is restarted. Since it is a foreground service, its process is almost never killed, so this doesn't happen.
The solution is to run the service and activity in their own processes by specifying:
android:process="name"
in AndroidManifest.xml