2013-01-23 98 views
4

我想在低内存条件下测试我的应用程序。以前我的方法是运行程序内存警告ios

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

但是以上都不起作用。

任何想法,将不胜感激

+1

单击如果当您使用模拟器硬件菜单(如你在回答您的评论暗示),它甚至不工作,那么它更可能问题在于你的功能。哪个班级没有收到该方法?它何时停止工作?你是否重写了这个方法而不叫超级? – jrturton

+0

我已经重写了这个方法,我叫超级。正如你所说,班级没有收到电话。 – TompaLompa

+0

是的,但哪些类? – jrturton

回答

1

看看这个帖子 Is there a way to send Memory Warning to iPhone device manually?

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

在模拟器:

硬件 - >模拟内存警告

+0

感谢您的答案。只是试了一下,它不会触发didReceiveMemoryWarning函数 – TompaLompa

+0

你也可能会尝试分配很多内存给一些虚拟变量 – Mikhail

+0

我不想采取这种方法 – TompaLompa

0

一个简单测试内存警告代码的方法是建立到模拟器和

硬件==>模拟内存警告

+0

我提到了编程.... – TompaLompa

+0

我没有注意到,抱歉。 – WolfLink

+0

不用担心..... – TompaLompa