UIApplication::didReceiveMemoryWarning -> UIApplicationDelegate::applicationDidReceiveMem
当一个controller收到内存警告时,需要释放一些当前不需要用到却能在需要时重新创建的资源。一个最明显的就是controller's view。以下是文档中关于收到low-memory时的处理流程:
The view controller calls its viewDidUnload method to inform subclasses that the views were removed. A subclass typically uses this method to release any strong references it has to those views.
You can use the viewDidUnload method to deallocate any data that is view specific and that can be re-created easily enough if the view is loaded into memory again. If re-creating the data might be too time-consuming, though, you do not have to release the corresponding data objects here. Instead, you should consider releasing those objects in your didReceiveMemoryWarning method.
Use this method to deallocate all noncritical custom data structures associated with your view controller. Although you would not use this method to release references to view objects, you might use it to release any view-related data structures that you did not already release in your viewDidUnload method. (The view objects themselves should always be released in the viewDidUnload method.)
重载didReceiveMemoryWarning时,一定调用这个函数的super实现来允许父类(一般是UIVIewController)释放self.view。self.view释放之后,会调用下面的viewDidUnload函数.也就是说,尽管self.view是被处理了,但是outlets的变量因为被retain过,所以不会被释放,为了解决这个问题,就需要在viewDidUnload中释放这些retain过的outlets变量。通常controller会保存nib文件建立的views的引用,但是也可能会保存着loadView函数创建的对象的引用。最完美的方法是使用合成器方法:
self.myCertainView = nil;
这样合成器会release这个view,如果你没有使用property,那么你得自己显式释放这个view。
iOS6.0及其以后,viewDidUnload不再有用,收到low-memeory时系统不会释放Views。
iOS6.0及以上版本的内存警告:
调用didReceiveMemoryWarning内调用super的didReceiveMemoryWarning调只是释放controller的resouse,不会释放view
处理方法: