Is there a way to send Memory Warning to iPhone device manually? [duplicate]

不羁的心 提交于 2019-12-04 01:36:32

You can manually simulate in the simulator:

Hardware -> Simulate Memory Warning

You can also simulate it programmatically:

- (void)simulateMemoryWarning
{
#if TARGET_IPHONE_SIMULATOR
  #ifdef DEBUG
    CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(),    (CFStringRef)@"UISimulatedMemoryWarningNotification", NULL, NULL, true);
  #endif
#endif
}

CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)@"UISimulatedMemoryWarningNotification", NULL, NULL, true);

Memory warning can be produced by calling an private method of UIApplication. It works fine on iOS 6.1 and below

  [[UIApplication sharedApplication]performSelector:@selector(_performMemoryWarning)];

NOTE: Remove that selector call before submitting app to iTunes, otherwise it will be rejected.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!