- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用这两种方法进行内存管理的最佳实践是什么?我当前的应用程序可以在内存警告后轻松释放其 View ,因为它需要大量内存。我需要在这些方法中做什么?我在应用程序中使用各种 Nib ,并将其中的对象连接到我的 View Controller 而不保留它们。从 Nib 加载 View 时是否需要保留 Nib 对象,为什么?我在文档中看到 OS 3.0 发生了变化,我只谈论 3.0
最佳答案
如果您只谈论 iOS 3.0,请在 viewDidUnload
中释放您可以轻松重新创建的任何对象。然后,您可以从 viewDidLoad 中的 Nib 重新创建或重新加载它们。确保当你释放对象时,要么将它们清零,要么让你的 setter 这样做。这样您就可以在重新加载或重新创建之前使用 viewDidLoad
检查是否为零。
对于从 nib 对象加载,如果您正在加载到属性中,并将它们设置为保留,则不必再次保留。
来自Apple :
The UIViewController class provides some automatic handling of low-memory conditions through its didReceiveMemoryWarning (page 20) method, which releases unneeded memory.
Prior to iPhone OS 3.0, this method was the only way to release additional memory associated with your custom view controller class but in iPhone OS 3.0 and later, the viewDidUnload (page 30) method may be a more appropriate place for most needs. When a low-memory warning occurs, the UIViewController class purges its views if it knows it can reload or recreate them again later. If this happens, it also calls the viewDidUnload method to give your code a chance to relinquish ownership of any objects that are associated with your view hierarchy, including objects loaded with the nib file, objects created in your viewDidLoad (page 29) method, and objects created lazily at runtime and added to the view hierarchy. Typically, if your view controller contains outlets (properties or raw variables that contain the IBOutlet keyword), you should use the viewDidUnload method to relinquish ownership of those outlets or any other view-related data that you no longer need.
关于iphone - 如何使用didReceiveMemoryWarning和viewDidUnload?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1460450/
模板似乎创建了 [super viewDidUnload] 但代码示例显示: [super dealloc] 有区别吗? 最佳答案 您应该只调用父类(super class)的 -viewDidUnl
我的问题是这样的: 父类加载 subview 。 子级在执行操作期间使用“removeFromSuperView”删除自身。 当子类被移除时,父类会获得委托(delegate)调用,从而使子对象为零。
也许这是一个不好的做法,但从我阅读的文档中,我得到了在某些情况下在 viewDidLoad 方法内初始化对象并在 viewDidUnload 中将其置零的建议。 例如,如果您有添加观察者之类的内容 [
我知道以前有人问过类似的问题。但是我已经搜索了一段时间了,事情仍然有些困惑。所以这里... 我没有使用 ARC。 如果您有一个带有实例变量和如下属性的 View Controller : View C
我在读一本书,它建议将我的 IBOutlets 声明为 weak 应该可以解决当我的应用程序收到内存不足警告时的问题。例如,我现在不再需要在 viewDidUnload 方法中将这些 socket 设
viewDidUnload 的最佳实践是什么?仅将 IBOutlets 设置为 nil 还是将每个实例变量也设置为 nil(之前释放)? 提前致谢。 最佳答案 在设置为 nil 之前释放实例变量。不过
在我的应用程序中,我有一个 UIImagePicker,它不断抛出内存警告级别 1(最低)。然后它不断搞乱我的应用程序,因为它正在调用 viewdidunload 或 viewwillunload。当
我正在尝试禁用选项卡栏上除第一个选项卡之外的所有选项卡。我想出了这段代码: -(void)disableMainTabBar{ [self setSelectedIndex:0];
我试图弄清楚如何挂接到控件的 super View 上的ViewDidUnload。为了说明我为什么需要这个,请考虑我的 ControlFactory 类,它生成 UIButton(以及其他控件):
我一直在阅读“iPhone 4 开发入门”一书,他们有一个使用导航 Controller 的教程。在本教程中,我们将 View Controller (名为 childController)推送到 V
注意:我看到前面有人问了几个问题,但似乎没有一个能澄清我的疑问。 在 iOS6 之前,所有 socket ,图像和声音等大量资源在 viewDidUnload 中设置为 nil。在 iOS6 之后,情
如果我有一个 viewController 设置如下: @interface MapViewController : UIViewController { CLLocationManager
我是 iPhone 开发新手。 我在我的应用程序中使用一些按钮和标签。我将在 dealloc 函数中释放所有这些按钮和标签。 我也在 viewDidUnload 中释放它们。 - (void)view
摘自 Apple 的 View Controller 编程指南/高效管理内存; didReceiveMemoryWarning Use this method to deallocate all no
我倾向于在 -dealloc 中释放我的东西,现在 iPhone OS 3.0 引入了这个有趣的 -viewDidUnload 方法,他们说: // Release any retained subv
注意:此问题已过时 - viewDidUnload 已在 iOS 6 中弃用。 什么时候UIViewController的viewDidUnload会自动被调用?是的,我知道,当 View 卸载时。但
我刚刚安装了新版本的Xcode/ios6。 viewDidUnload 现已弃用。 在苹果文档中, viewDidUnload [...] Deprecated in iOS 6.0. Views a
当我移动到另一个 View 时,我可以使用哪种方法来捕获事件? 到目前为止我尝试过但没有成功的方法:viewWillDisappear: , willMoveToParentViewControlle
我一直在开发一个应用程序,我读的书说将这些语句放入 viewDidUnload 和 dealloc 方法中。还有什么其他信息应该放在这里?我的程序中有按钮和标签。我需要为他们做些什么吗? 我想要一个高
我遇到了一个非常有趣的情况,不知道如何解决它。我将首先概述我的程序的体系结构。我有一个 UITableViewController 派生类,它也实现了我的委托(delegate)协议(protocol
我是一名优秀的程序员,十分优秀!