我从来没有亲眼见过 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 theviewWillUnload
andviewDidUnload
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 yourviewDidLoad
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 thedidReceiveMemoryWarning
method.
关于阈值,我尽量不要超过12MB内存。
关于iphone - didReceiveMemoryWarning 什么时候实际调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12968879/