2013-01-23 69 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