1

I'd like to perform the memory test of my android package.

In my package, there is only one very simple service.

The service is started only by bindService from another package. (not startService)

After, another package (package 1) calls bindService to my package, the package termintates. Then the log of my package is as follows.

04-04 16:13:06.962 5468-5468/memorytestapp I/: @onCreate

04-04 16:13:06.966 5468-5468/memorytestapp I/: @onBind

04-04 16:13:12.221 5468-5468/memorytestapp I/: @onUnbind
04-04 16:13:12.258 5468-5468/memorytestapp I/: @onDestroy

After onDestroy is called, I expect that my package do not resides in RAM after certain time.

However, even though the package 1 (caller) do not resides in RAM right after the termination, my packagee (callee) still resides in RAM continuously.

After 3 hours, when I enter the 'adb sehll dumpsys activity oom | grep my package name' to check the memory status, it shows this line.

Proc # 5: cch B/ /CEM trm: 0 5468:memorytestapp/u0a227 (cch-empty)

Although my package is in cached status, it still resides in RAM continuously. Even when I insert the code "stopService or stopSelf" at onDestroy, it has same status!

I really want my package not to reside in RAM after onDestroy is called.

Is there any opinion or comment to this situation??

Sincerely, Logan.

Source code of my package is as follows.

public class TestService extends Service {

    @Override
    public void onCreate(){
        super.onCreate();
    }

    @Override
    public void onDestroy(){
        super.onDestroy();
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public boolean onUnbind(Intent intent) {
        return true;
    }

    @Override
    public void onRebind(Intent arg0){
    }
}
kgandroid
  • 5,507
  • 5
  • 39
  • 69
Logan
  • 31
  • 1
  • 4

1 Answers1

1

Services are cached after calling stopservice(). They are called empty process.

A process that doesn't hold any active application components. The only reason to keep this kind of process alive is for caching purposes, to improve startup time the next time a component needs to run in it. The system often kills these processes in order to balance overall system resources between process caches and the underlying kernel caches.

See this link and read about empty process.

However you can kill a process forcefully by using :

int pid = android.os.Process.myPid();
android.os.Process.killProcess(pid);
kgandroid
  • 5,507
  • 5
  • 39
  • 69
  • Oh, thank you for your response! In my test cases, I saw only one time that my package disappear in RAM. In this case, the log is as follows. Killing 19191: 'my package name': empty for 1800s. A lot of other packages also disappear with this log. From this log, I noticed that generally after being cached 1800s, the package will disappear in RAM. However, my package usually resides in RAM. (except for only one case) Based on your comment, this is because the resource balancing is not required in my situation. Is it right? Thanks in advance. :-) – Logan Apr 05 '18 at 06:29
  • Android ranks a process at the highest level it can, based upon the importance of the components currently active in the process. For example, if a process hosts a service and a visible activity, the process is ranked as a visible process, not a service process. – kgandroid Apr 05 '18 at 07:06