开发者

startService() and stopService() and memory.. what is happening?

this is just a general question about android with no particular use case in mind. As I am currently still learning the platform, I have been doing some experimentation with services.

I have created a class called TestService that extends service. I have not made any changes to the code nor done anything inside the service. In essence, it is just an empty service. This is what I mean:

    public class TestService extends Service {
    @Override
        public IBinder onBind(Intent intent) {      
            return null;
        }
    }

Using the following code, I start the service in my activity:

    Intent sIntent = new Intent();
    sIntent.setClassName("com.mytestapp.android.servicetest", 
            "com.mytestapp.android.servicetest.TestService");
    startService(sIntent);

And to stop it, I call:

    stopService(sIntent);

Now to monitor if my service is actually started, I accessed the running services list provided by android by going to Settings -> Applications -> Running Services. And well, it works.. the serv开发者_JAVA百科ice shows up there.

One thing I have noticed, however, is that EVERYTIME i stop and start my service again, the memory used by the service seems to be INCREASING (as shown by the running services information). After doing it for about twenty times, the memory used by the service increased by almost 50% of the original!

I find this to be strange, and I'm wondering if anyone can explain what seems to be happening here? Is this normal?


Is this normal?

Most likely, those Service objects have not been garbage collected yet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜