当iPhone从睡眠中恢复并且应用仍处于打开状态时解除分配 [英] Deallocation when iPhone is turned back on from sleep and app is still open

查看:273
本文介绍了当iPhone从睡眠中恢复并且应用仍处于打开状态时解除分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有几个实例,当我的应用程式从睡眠中恢复后,应用程式崩溃,但应用程式仍然开启。它发生,如果一个UITableViews是打开的,当iPhone进入睡眠;该表正在从解析的XML中填充。我明白为什么它崩溃了;在我的viewDidUnload方法我释放填充表的数组。如何处理这个我不知道;是的我可以简单地不释放它在viewDidUnload,但然后它永远不会留下内存,如果你返回到主菜单。

There are a few instances where my app crashes when turned back on from sleep and the app is still open. It happens if a UITableViews is open when the iPhone is put into sleep; the table is being filled from an XML being parsed. I understand why it is crashing; in my viewDidUnload method I am releasing the array that is filling the table. How to handle this I am not sure; yes I could simply not release it in viewDidUnload, but then it would never leave memory if you returned to the main menu.

任何帮助将不胜感激。

推荐答案

方法viewDidUnload不是正确的地方发布你的数据,如果在所有。我引用苹果的文档,它比我可以更好地描述它:

The method viewDidUnload is not the right place to release your data if at all. I quote Apple's documentation, which desribes it better than I could:


这个方法被调用作为对应的
到viewDidLoad方法。在低内存条件期间
被调用
当视图控制器需要
释放其视图和与该视图相关联的任何对象
释放
内存。因为视图控制器经常
存储对视图和其他
视图相关对象的引用,所以你应该使用
这个方法放弃
这些对象的所有权,使
他们可以回收。你应该做的
这只为对象,你可以
轻松地重新创建,在你的
viewDidLoad方法或从应用程序的其他部分
您不应该
使用此方法发布用户数据

或任何其他不能
的信息都很容易重新创建。

This method is called as a counterpart to the viewDidLoad method. It is called during low-memory conditions when the view controller needs to release its view and any objects associated with that view to free up memory. Because view controllers often store references to views and other view-related objects, you should use this method to relinquish ownership in those objects so that the memory for them can be reclaimed. You should do this only for objects that you can easily recreate later, either in your viewDidLoad method or from other parts of your application. You should not use this method to release user data or any other information that cannot be easily recreated.

ViewDidUnload仅用于释放视图相关对象。视图控制器可以释放它的视图,因为它没有显示,仍然是你的控制器的实例存在,你的模型也是如此。

ViewDidUnload is used only to release view related objects. A view controller can release its view because its not shown, still your instance of that controller exists and so does your model.

这篇关于当iPhone从睡眠中恢复并且应用仍处于打开状态时解除分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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