我有一个简单的 Hello World 应用程序
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,我看到ctr每次都增加,表明Activity在BACK后没有完全杀死。
这也可以通过在按下 BACK 后在 DDMS 中转储 HPROF 文件来确认。
该文件仍然包含我的 TestLeaksOnFinish 活动类。
有人可以解释为什么按 BACK 后这个 Activity 仍然存在于堆转储中吗?
当我列出传入的引用时,我得到以下