您的位置:首页 > 移动开发

关于iPhone App的 Memory warning的一点东西

2013-05-22 12:56 393 查看


iPhone App 现在进入到了iOS4时代,内存问题越来越重要了,以前的iOS都是单任务的,内存还算够用,现在iOS4推出了多任务系统,越来越多的程序占了内存以后,在后台又不释放,使用者也往往会忘记在后台杀掉其他程序的进程,导致现在的程序经常会遇到内存不够用的情况,真不知道这个多任务系统是好是坏丫。

总之,作为一个程序员,有bug就得处理,没办法。。。

接收到内存不够警告很有必要,使用

- (void)didReceiveMemoryWarning {

         [super didReceiveMemoryWarning];

         //TO DO:

}

如果内存不够用,这个方法就能触发了。这时候,建议你释放一些必不要的数据以便腾出足够的内存。

好吧,我承认前面都是废话,下面写点有用的, 关于内存警告级别的解释:

There are 4 levels of warnings (0 to 3). These are set from the kernel memory watcher, and can be obtained by the not-so-public function OSMemoryNotificationCurrentLevel().

typedef enum {

    OSMemoryNotificationLevelAny      = -1,

    OSMemoryNotificationLevelNormal   =  0,

    OSMemoryNotificationLevelWarning  =  1,

    OSMemoryNotificationLevelUrgent   =  2,

    OSMemoryNotificationLevelCritical =  3

} OSMemoryNotificationLevel;

How the levels are triggered is not documented. SpringBoard is configured to do the following in each memory level:

    1.    Warning (not-normal) — Relaunch, or delay auto relaunch of nonessential background apps e.g. Mail.

    2.    Urgent — Quit all background apps, e.g. Safari and iPod.

    3.    Critical and beyond — The kernel will take over, probably killing SpringBoard or even reboot.

Killing the active app (jetsam) is not handled by SpringBoard, but launchd.

根据我的理解,2级以前的警告都可以无视,2级的警告老实说,有点危险,但是我个人的体会是,其实也可以凑合了^_^

因为你如果使用了照相机的话,2级警告其实比较常见
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: