为什么退出Android后将应用程序及其资源保留在内存中? [英] Why the Application and it's resources are being kept in the memory after exiting in Android?

查看:122
本文介绍了为什么退出Android后将应用程序及其资源保留在内存中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Hello World应用程序

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);          
    }   
}

当我多次运行该命令时,每次按BACK(返回)后,每次点击率都会增加,这表明在BACK(返回)后,Activity并没有被完全杀死.

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.

也可以通过在按BACK后将HPROF文件转储到DDMS中来确认.
该文件仍然包含我的TestLeaksOnFinish活动类.

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

有人可以解释为什么在按BACK后该活动仍存在于堆转储中吗?

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

推荐答案

在Android活动中,您不会被杀死,它们只会被移到后台.这就是Android的工作方式,您无法杀死Application,或者基本上不会退出.它只会留在后台和内存中.

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.

这篇关于为什么退出Android后将应用程序及其资源保留在内存中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆