gpt4 book ai didi

iphone - UIViewController View 即使在可见时也被卸载

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

我有一个 View Controller A 以模态方式显示在导航 Controller 容器内的另一个 View Controller B 之上。当以模态方式显示此 View Controller A 时模拟内存警告时,我按预期收到 didReceiveMemoryWarnings 消息,然后收到消息 viewDidUnload,从而使我的 View Controller A 的 View 消失。

这让我感到惊讶,我不确定如何解决这个问题。为什么会调用viewDidUnload,释放进程中的可见view?

这是一个堆栈跟踪,以防它有助于查明问题:

[UIViewController unloadViewForced:] ()

0x01458535 in -[UIViewController unloadViewIfReloadable] ()

0x01463eb8 in -[UINavigationController purgeMemoryForReason:] ()

0x01457b6d in -[UIViewController didReceiveMemoryWarning] ()

感谢您的帮助!

最佳答案

根据 http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html

Memory Management

Memory is a critical resource in iOS, and view controllers provide built-in support for reducing their memory footprint at critical times. The UIViewController class provides some automatic handling of low-memory conditions through its didReceiveMemoryWarning method, which releases unneeded memory. Prior to iOS 3.0, this method was the only way to release additional memory associated with your custom view controller class but in iOS 3.0 and later, the viewDidUnload 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 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 模拟器上做同样的实验,并没有调用viewDidUnload 方法。我认为当内存非常低时,您的行为会发生。

关于iphone - UIViewController View 即使在可见时也被卸载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6617190/

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