iphone - didReceiveMemoryWarning 什么时候实际调用

标签 iphone ios memory ios6 didreceivememorywarning

我从来没有亲眼见过 didReceiveMemoryWarning 调用过。调用时是否存在已知的内存使用阈值?

最佳答案

当系统内存不足时调用它,然后您需要清除您的UIViewController

您可以在模拟器中模拟内存警告:Hardware > Simulate Memory Warning 看看会发生什么。

如果您支持 iOS6 之前的版本,请务必注意 Apple's documentation 中的以下内容:

Prior to iOS 6, when a low-memory warning occurred, the UIViewController class purged its views if it knew it could reload or recreate them again later. If this happens, it also calls the viewWillUnload and viewDidUnload methods to give your code a chance to relinquish ownership of any objects that are associated with your view hierarchy, including objects loaded from the nib file, objects created in your viewDidLoad method, and objects created lazily at runtime and added to the view hierarchy. On iOS 6, views are never purged and these methods are never called. If your view controller needs to perform specific tasks when memory is low, it should override the didReceiveMemoryWarning method.

关于阈值,我尽量不要超过12MB内存。

关于iphone - didReceiveMemoryWarning 什么时候实际调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12968879/

相关文章:

iphone - 从服务器获取数据到 iPhone sdk

iphone - 实现运行时多态性和继承

iphone - 如何在 iPhone Xcode 中自定义 UIPickerView 减少其尺寸?

memory - OpenCL 内存架构和 GPU 物理内存/缓存(L1/L2...)之间的关系?

php - 受内存/大小限制反序列化

android - 如何启用安卓显示器?

iPhone.如何在检测到声音时开始录音,检测到静音时停止录音

swift - 键盘上方的 View 不显示

ios - 一次在 tableviewcell 中显示一个单词

iOS Swift - 多个事件指示器(旋转器)出现在 web View 中