gpt4 book ai didi

iphone - 当 iPhone 从 sleep 状态重新打开且应用程序仍处于打开状态时释放

转载 作者:行者123 更新时间:2023-11-29 05:05:14 25 4
gpt4 key购买 nike

在某些情况下,当我的应用程序从 sleep 状态重新打开且应用程序仍处于打开状态时会崩溃。如果当 iPhone 进入休眠状态时 UITableViews 打开,就会发生这种情况;该表是从正在解析的 XML 中填充的。我明白为什么它会崩溃;在我的 viewDidUnload 方法中,我正在释放填充表格的数组。我不确定如何处理这个问题;是的,我可以简单地不在 viewDidUnload 中释放它,但是如果您返回主菜单,它永远不会留下内存。

如有任何帮助,我们将不胜感激!

最佳答案

viewDidUnload 方法根本不是释放数据的正确位置。我引用苹果的文档,它比我能更好地描述它:

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 仅用于释放 View 相关对象。 View Controller 可以释放其 View ,因为它未显示,但该 Controller 的实例仍然存在,您的模型也存在。

关于iphone - 当 iPhone 从 sleep 状态重新打开且应用程序仍处于打开状态时释放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5676603/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com