运行过程中遇到内存警告的话,程序通常情况下都先调用AppDelegate中的applicationDidReceiveMemoryWarning, 然后程序会通知各ViewController,调用其didRecieveMemoryWarning方法,这个时候我们一定要种,释放不必要的资源
输出内存级别:系统将会发出更高一级的内存警告 level 2,通常的结果就是我们的App被强制退出,系统收回内存;一般当收到level 1的内存警告时就应该自己在程序中回收内存了,否则当收到level 2时,应用就有可能被强退了。
#import <libkern/OSMemoryNotification.h>
- (void)didReceiveMemoryWarning
{
NSLog(@"Recieve memory warning");
NSLog(@"~~~~~~~~~~~~~~level~~~~~~~~~~~~~~~ %d", (int)OSMemoryNotificationCurrentLevel());
}
内存管理参考文章: