有没有办法手动向iPhone设备发送内存警告?

有没有办法手动向iPhone设备发送内存警告?,iphone,ios,xcode,cocoa-touch,memory-warning,Iphone,Ios,Xcode,Cocoa Touch,Memory Warning,这些天我有一个问题。我使用的是一个图像缓存库,它工作得很好,但最终我遇到了内存问题,应用程序自行退出(我想这是因为它的内存不足)。在阅读了图像缓存库的源代码后,我发现它说当出现内存警告事件时,它会释放所有缓存的图像(图像很大)。我是否可以手动直接向设备发送内存警告事件?我正在使用xcode instrument工具评估内存使用情况。您可以在模拟器中手动模拟: Hardware -> Simulate Memory Warning 您还可以通过编程方式对其进行模拟: - (void)sim

这些天我有一个问题。我使用的是一个图像缓存库,它工作得很好,但最终我遇到了内存问题,应用程序自行退出(我想这是因为它的内存不足)。在阅读了图像缓存库的源代码后,我发现它说当出现内存警告事件时,它会释放所有缓存的图像(图像很大)。我是否可以手动直接向设备发送内存警告事件?我正在使用xcode instrument工具评估内存使用情况。

您可以在模拟器中手动模拟:

Hardware -> Simulate Memory Warning
您还可以通过编程方式对其进行模拟:

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

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

通过调用UIApplication的私有方法可以生成内存警告。它在iOS 6.1及以下版本上运行良好

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

注意:在向iTunes提交应用程序之前,请删除该选择器调用,否则将被拒绝

提到了一个未记录的API,在将应用程序提交给苹果之前不要忘记删除它,只用于测试,否则你的应用程序将被拒绝。这在iOS 7的Xcode 5中没有任何作用