程序化内存警告ios

时间:2013-01-23 07:40:44

标签: iphone ios objective-c memory-management

我想在内存不足的情况下测试我的应用。以前我的方法是运行

[NSTimer scheduledTimerWithTimeInterval:2.0 target:[UIApplication sharedApplication] selector:@selector(_performMemoryWarning) userInfo:nil repeats:YES];

但它不再起作用了。通过工作我的意思是不调用 didReceiveMemoryWarning 。我也试过了:

 [[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidReceiveMemoryWarningNotification object: [UIApplication sharedApplication]]; 
 [[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidReceiveMemoryWarningNotification object: nil];
 [[UIApplication sharedApplication] _performMemoryWarning];

但上述情况似乎都不起作用。

任何想法都将不胜感激

2 个答案:

答案 0 :(得分:1)

看看这篇文章 Is there a way to send Memory Warning to iPhone device manually?

以编程方式发送:CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)@"UISimulatedMemoryWarningNotification", NULL, NULL, true);

在模拟器中:

硬件 - >模拟记忆警告

答案 1 :(得分:0)

测试内存警告代码的一种简单方法是构建模拟器并单击

  

硬件==>模拟记忆警告