IOS如何管理后台应用程序的内存? [英] How does IOS manage memory of backgrounded apps?

查看:80
本文介绍了IOS如何管理后台应用程序的内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个IOS应用程序,在测试过程中似乎可以正常工作,直到...

I have an IOS app that during testing seems to work fine until...

该应用程序已经在后台运行了很长时间,例如24小时...,与此同时,其他应用程序中也发生了很多活动(视频,音频,位置信息,电池电量低,内存不足)被使用).

The app has been in the background for quite some time, say 24 hours... and meanwhile lots of activity has taken place in other apps (videos, audio, location... battery going low... lots of memory being used).

然后,当我将我的应用重新放回前台时,它就会出现故障,例如没有音频...,然后在不久后崩溃.

Then when I bring my app back into the foreground, it acts glitchy such as having no audio... and then crashes after a short while.

我知道这不是最好的描述,但它只发生过一次,我并没有要求任何人确切地告诉我问题出在什么地方.

I KNOW this is not the best description, but it has only happened once and I'm not asking anyone to tell me exactly what the problem is.

我真正想知道的是:

IOS是否会对后台应用程序执行任何操作,例如从内存中丢弃它们可能需要的对象?我认为,如果这样做,它将在下次恢复应用程序时重新启动该应用程序,而不是尝试恢复不可恢复的应用程序.

Does IOS do anything with backgrounded apps such as tossing out objects they may need from memory? I would think that if it did do this, then it would restart the app the next time it's resumed rather than attempting to resume the un-resumable.

谢谢!

推荐答案

如果内存不足,系统可能认为有必要释放一些内存,并且希望您通过实现 UIApplicationDelegate 方法 applicationDidReceiveMemoryWarning UIViewController方法 didReceiveMemoryWarning .

The system may deem it necessary to free up some memory if it's running low on it, and is expecting you to handle such situations by implementing UIApplicationDelegate method applicationDidReceiveMemoryWarning and UIViewController method didReceiveMemoryWarning.

这些方法的文档没有提及调用这些方法时系统在后台执行的操作(只是您应释放尽可能多的内存,否则您的应用可能会终止),但是此博客文章声称该系统可能破坏内部对象,例如图形上下文或内部存储.

Documentation for those methods don't mention what does the system do behind the scenes when those methods are called (only that you should free up as much memory as possible, otherwise your app may get terminated), but this blog post claims that the system may destroy internal objects like graphic contexts or internal stores.

这篇关于IOS如何管理后台应用程序的内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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