How does IOS manage memory of backgrounded apps?

你离开我真会死。 提交于 2021-01-29 06:55:28

问题


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

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.

What I would really like to know is:

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.

Thanks!


回答1:


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.



来源:https://stackoverflow.com/questions/50406686/how-does-ios-manage-memory-of-backgrounded-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!