有没有办法手动发送内存警告到iPhone设备? [英] Is there a way to send Memory Warning to iPhone device manually?

查看:189
本文介绍了有没有办法手动发送内存警告到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);

这篇关于有没有办法手动发送内存警告到iPhone设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆