您现在的位置是:首页 > 电脑 > 

内存警告后SMutableArray清除(SMutableArray Clearing after Memory Warning)

2025-07-19 11:13:25
内存警告后SMutableArray清除(SMutableArray Clearing after Memory Warning) 我有一个程序将捕获的图像保存到SMutableArray临时。 通常情况下这很好,但如果我有一堆其他应用程序正在运行并且我捕获了一个图像,我会得到一个内存警告,当发生这种情况时,SMutableArray中的图像会丢失,然后
内存警告后SMutableArray清除(SMutableArray Clearing after Memory Warning)

我有一个程序将捕获的图像保存到SMutableArray临时。 通常情况下这很好,但如果我有一堆其他应用程序正在运行并且我捕获了一个图像,我会得到一个内存警告,当发生这种情况时,SMutableArray中的图像会丢失,然后我才能保存它。 有没有办法防止iOS清除此SMutableArray,直到我完成它,即使发生内存错误? 谢谢。

I have a program that is saving a captured image to a SMutableArray temporary. ormally this is fine, but if I have a bunch of other applicati running and I capture an image I get a Memory Warning, when this happens the image in the SMutableArray is lost before I can save it. Is there a way to prevent iOS from clearing this SMutableArray until I am done with it even if a memory error occurs? Thank you.

最满意答案

如果要在控制器上创建数组,则会出现问题-(void) loadView或-(void) viewDidLoad方法。

在内存警告之后,控制器可能会将view属性设置为nil ,这将导致调用控制器的viewDidUnload方法。 我想到目前为止这对你来说还不错。

问题是在调用viewDidUnload之后,如果有任何尝试访问控制器view属性(比如通过在解除模态后显示视图,或者通过弹出到控制器),将再次调用loadView和viewDidLoad方法, ,如果您使用这两种方法中的任何一种设置数组,您将丢失以前的数据,因为您将再次设置该数组

编辑:

这对于iOS 5+无效,因为不推荐使用viewDidUnload方法,并且永远不会在UIViewController生命周期中调用它

http://developer./library/ios/#documentation/uikit/reference/UIViewController_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instm/UIViewController/viewDidUnload

You will have a problem if you are creating your array at the controller -(void) loadView or -(void) viewDidLoad method.

After a memory warning, the controller might set the view property to nil, which will cause the method viewDidUnload of your controller to be called. I guess this is fine for you so far.

The problem is that after the viewDidUnload is called, if there is any attempt to access the controller view property (like by displaying the view after dismissing a modal, or by popping to the controller), the loadView and viewDidLoad method will be called again and, if you are setting the array in any of this two methods, you will lose your previous data because you will be setting the array again

EDIT:

This is not valid for iOS 5+ as the viewDidUnload method was deprecated and is never called in the UIViewController lifecycle

http://developer./library/ios/#documentation/uikit/reference/UIViewController_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instm/UIViewController/viewDidUnload

#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格

本文地址:http://www.dnpztj.cn/diannao/61867.html

相关标签:无
上传时间: 2023-04-21 00:31:23
留言与评论(共有 14 条评论)
本站网友 美国签证预约
6分钟前 发表
将再次调用loadView和viewDidLoad方法
本站网友 尼康镜头大全
16分钟前 发表
如果您使用这两种方法中的任何一种设置数组
本站网友 卖房子
2分钟前 发表
when this happens the image in the SMutableArray is lost before I can save it. Is there a way to prevent iOS from clearing this SMutableArray until I am done with it even if a memory error occurs? Thank you. 最满意答案 如果要在控制器上创建数组
本站网友 嘉兴二手房网
30分钟前 发表
the controller might set the view property to nil
本站网友 李文龙
18分钟前 发表
//developer./library/ios/#documentation/uikit/reference/UIViewController_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instm/UIViewController/viewDidUnload
本站网友 杨云聪
13分钟前 发表
控制器可能会将view属性设置为nil
本站网友 怀孕28周
21分钟前 发表
当发生这种情况时
本站网友 plot函数
10分钟前 发表
并且永远不会在UIViewController生命周期中调用它 http
本站网友 信封怎么写
21分钟前 发表
or by popping to the controller)
本站网友 步入
14分钟前 发表
内存警告后SMutableArray清除(SMutableArray Clearing after Memory Warning) 我有一个程序将捕获的图像保存到SMutableArray临时
本站网友 小肥羊团购
4分钟前 发表
这将导致调用控制器的viewDidUnload方法
本站网友 枫叶的资料
22分钟前 发表
or by popping to the controller)
本站网友 百度分享代码
2分钟前 发表
即使发生内存错误? 谢谢