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

标签 java android android-activity memory-leaks

我无法理解来自 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/

相关文章:

java - 为eclipse添加spring资源

android - 我怎样才能在 NestedScrollView 中使用 RecyclerView 工作 ViewPager

Android: "Cannot Resolve symbol ' addValueEventListener'"在 Firebase 中

android - Android编程中无法从Fragment切换到Activity/Activity到Fragment

Android:如何从 BroadcastReceiver 恢复应用程序/Activity ?

android - 有没有办法让 Android 相机记录经历多个 Activity ?

java - 哪个插件贡献了 Java 视角?

Java:两个平行列格式

java - Vaadin:集中自定义异常处理

java - 在android中保持时间