【iOS6後的內存警告處理】html
The memory used by a view to draw itself onscreen is potentially quite large. However, the system automatically releases these expensive resources when the view is not attached to a window. The remaining memory used by most views is small enough that it is not worth it for the system to automatically purge and recreate the view hierarchy.ios
iOS6後UIKit框架會自動將view中的圖片資源給釋放掉,而不會將view對象自己給釋放掉。由於和位圖內存相比,view對象自己所佔內存小到能夠忽略。因此iOS6起後,didReceiveMemoryWarning默認會作的事情是把把位圖資源釋放掉,簡而言之就是程序員不用再考慮了,UIKit會自動作。而view對象都會被保留。
程序員
若是程序員須要本身釋放資源,能夠這像下面這樣寫。app
- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Add code to clean up any of your own resources that are no longer necessary. if (self.isViewLoaded && [self.view window] == nil) { // Add code to preserve data stored in the views that might be // needed later. // Add code to clean up other strong references to the view in // the view hierarchy. self.view = nil; }
iOS5默認會釋放位圖資源與卸載view對象,iOS6默認只釋放位圖資源。而爲了統一處理,能夠用上述代碼,iOS6後自主卸載view對象。另外viewWillUnload與viewDidUnload這2個方法就沒有意義了,把想關代碼都移到上述代碼中便可。框架