4

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

[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];

但上述方法似乎都不起作用。

任何想法,将不胜感激

4

2 回答 2

1

看看这篇文章 有没有办法手动向 iPhone 设备发送内存警告?

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

在模拟器中:

硬件 -> 模拟内存警告

于 2013-01-23T07:46:56.583 回答
0

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

硬件 ==> 模拟内存警告

于 2013-01-23T08:15:31.630 回答