有没有办法手动发送内存警告到iPhone设备?
我有一个问题,这些天。我使用的图像缓存库,它的工作原理很好,但最终我遇到内存问题,应用程序只是退出本身(我猜是因为它只是耗尽内存)。从图像缓存库中读取源代码后,我发现它说,当有内存警告事件时,它会释放所有缓存的图像(图像是巨大的)。有没有反正为我手动和直接发送内存警告事件到设备?
I got one problem these days. I'm using an image-cache library, it works well but eventually i met memory issue and the app just quit itself (I guess it's because it just runs out of memory). After read the source code from the image-cache library, i found it's said that when there's memory warning event, it would release all images cached (the images are huge). Is there anyway for me to send Memory warning event to the device manually and directly ? I'm using xcode instrument tool to evaluate the memory usage.
您可以在模拟器中手动模拟:
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);