当应用程序在后台时没有收到 didReceiveMemoryWarning

发布于 2024-11-08 22:58:21 字数 600 浏览 0 评论 0原文

我注意到,当我的应用程序在 iPad 模拟器上处于后台状态时,我的视图控制器没有调用其 didReceiveMemoryWarning 方法。更具体地说,我在日志中看到对 applicationDidEnterBackground 的调用,然后单击“模拟内存警告”按钮,然后我注意到没有任何 didReceiveMemoryWarning 调用。

但是,当我将应用程序带回前台时,我突然收到 didReceiveMemoryWarning 调用,就好像它已排队一样。

我在这里感到困惑的是我的应用程序是否真的在后台,或者它只是完全挂起。有什么办法可以在模拟器中判断吗?

另外,如果它尚未暂停,并且确实只是在后台,那么我会发现无法处理 didReceiveMemoryWarning 是很愚蠢的。因为这意味着只有前台应用程序可以处理内存警告以释放空间,这当然很奇怪,因为前台应用程序可能只是可能数十个正在运行的应用程序之一,并且如果它们都可以释放内存。

无论如何,主要问题是:为什么我没有在后台状态下获得 didReceiveMemoryWarning ?还有,我真的被停职了吗?我怎么知道呢?

I'm noticing that my view controllers aren't getting their didReceiveMemoryWarning methods called when my application is in the background state on the iPad simulator. More specifically, I see the call to applicationDidEnterBackground in my logs, then I hit the "Simulate Memory Warning" button, and then I notice a peculiar lack of any didReceiveMemoryWarning calls.

However, when I bring the application back to the foreground I suddenly get the didReceiveMemoryWarning call, as if it had been queued.

What I'm confused about here is if my application is really in the background, or if it's just flat out suspended. Is there any way to tell in the simulator?

Also, if it is not yet suspended, and really is just in the background, then I would find it silly that I'm unable to process didReceiveMemoryWarning. Because that would then mean that only the foreground application can process memory warnings to free up space, which is of course odd given that the foreground app could be only one of possibly dozens of running apps, and it would make so much more sense if they could all free up memory.

Anyway, the main questions are: why aren't I getting didReceiveMemoryWarning in the background state? And also, am I really suspended? And how do I tell?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

潦草背影 2024-11-15 22:58:21

如果您没有启动后台任务,或者在后台进行 VOIP、位置跟踪或音频,那么您的应用程序将在 applicationDidEnterBackground 之后挂起。它不会收到任何通知。所有通知都会保留(即使是应用程序暂停后发生的通知),并在应用程序再次转到前台时发送到应用程序。

If you did not start a background task, or do VOIP, location tracking or audio in the background, then your app is suspended after applicationDidEnterBackground. It will not get any notifications. Any notifications are kept around (even those that occur after the app was suspended) and sent to the app when the app goes to the foreground again.

温折酒 2024-11-15 22:58:21

我认为情况并非如此。我可以在后台访问 didReceiveMemoryWarning 代码。一旦系统产生比好公民低的内存信号,我们就应该释放内存。这也有助于我们的应用程序不被系统终止。

I don't think that is the case. I am able to access didReceiveMemoryWarning code while in background. Once system generates low memory signal than as a good citizen we should release the memory. This also helps our app from terminating by the system.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文