Why the Application and it's resources are being kept in the memory after exiting in Android?

时光总嘲笑我的痴心妄想 提交于 2019-12-23 17:48:02

问题


I have a simple Hello World application

public class TestLeaksOnFinish extends Activity  
{
    static int ctr = 0;
    protected void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    TextView t = new TextView(this);
    t.setText("Hello World! "+ctr++);
    setContentView(t);          
    }   
}

When I run this multiple times, each time followed by pressing BACK, I see that ctr increases each time, indicating that the Activity is not killed completely after BACK.

This is also confirmed by dumping the HPROF file in DDMS after pressing BACK.
This file still contains my TestLeaksOnFinish activity class.

Can someone explain why this Activity is still present in the heap dump after pressing BACK?

When I list the incoming references, I get the following


回答1:


In Android activities dont get killed they'll just be moved to background.That's how Android works you cant kill an Application or basically there's not quit as you know.It'll just stay in the background and in the memory.

When you run out of memory then the system starts to kill the Application processes according to priority that the system gives to every application itself.



来源:https://stackoverflow.com/questions/8149017/why-the-application-and-its-resources-are-being-kept-in-the-memory-after-exitin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!