gpt4 book ai didi

ios - 问题:消息发送到已释放实例

转载 作者:行者123 更新时间:2023-12-02 08:05:44 24 4
gpt4 key购买 nike

我在HomeViewController中有一些代码。当我打开下一个 Controller 并点击按钮并执行

let strotyboard = UIStoryboard(name: "Anketa", bundle: nil)
if let anketaController = strotyboard.instantiateViewController(withIdentifier: "QuestionnaireViewController") as? QuestionnaireViewController {
anketaController.startNew = true
print("1111 HomeViewController openNext , ", anketaController)
present(anketaController, animated: true, completion: nil)
}
当我返回 HomeViewController并再次点击按钮以打开 QuestionnaireViewController时,这是一条错误消息:

"QuestionnaireViewController retain]: message sent to deallocated instance 0x10480a400"


我打印了 print("1111 HomeViewController openNext , ", anketaController),第一次点击按钮是:
1111 HomeViewController openNext ,  <.QuestionnaireViewController: 0x10480a400>
在第二个点击的按钮上是:
1111 HomeViewController openNext ,  <.QuestionnaireViewController: 0x10901fa00>
并且该应用在iOS 13上崩溃

最佳答案

奥默尔的答案可能是正确的。我自己创建保留循环有很多麻烦(即使经过很多时间)。帮助我的是this idea of doing an extension to UIViewController that makes a delayed check on the self pointer to make sure it's deallocated
如果2秒钟后未释放 View Controller ,则您肯定会泄漏,因此断言将停止您的代码,您可以使用XCode的Memory Graph功能,找到 View Controller 并查看使它保持 Activity 状态的原因。

关于ios - 问题:消息发送到已释放实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62691721/

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