gpt4 book ai didi

java - 即使应用程序被杀死,我们也会发生内存泄漏吗?

转载 作者:太空宇宙 更新时间:2023-11-03 12:17:30 25 4
gpt4 key购买 nike

我无法理解来自 Activity.onStop() 的声明:

When your activity receives a call to the onStop() method, it's no longer visible and should release almost all resources that aren't needed while the user is not using it. Once your activity is stopped, the system might destroy the instance if it needs to recover system memory. In extreme cases, the system might simply kill your app process without calling the activity's final onDestroy() callback, so it's important you use onStop() to release resources that might leak memory.

特别是这部分:

In extreme cases, the system might simply kill your app process without calling the activity's final onDestroy() callback, so it's important you use onStop() to release resources that might leak memory

如果进程被杀死,如果我们在onStop 中没有释放代码,我们怎么会发生内存泄漏?在应用程序终止时,所有资源都被清除了吗?

最佳答案

If the process is killed how can we get a memory leak if we don’t have release code in onStop?

你不能。 Android 文档有问题,哟。

On app kill all resources are cleaned right?

好吧,您的进程已终止,这消除了您的 RAM 和线程。您需要做的是安排清理与您的 RAM 和线程相关的所有内容。例如,如果用户已将数据输入到您想要保留但尚未保留的应用程序中,onStop() 是考虑 fork 线程以将这些内容保存到磁盘的候选时间。

关于java - 即使应用程序被杀死,我们也会发生内存泄漏吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29922793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com