我正在创建一个 ViewController 对象并将其推送到导航控制器.当对象从堆栈中弹出时 - 它没有被释放并且 Deinit 没有被调用.这可能是什么原因?
I'm creating a ViewController object an pushing it to a navigation controller. When the object is being popped from the stack - it is not being release and Deinit is not being called. What can be the reason for that?
这是推送的代码:
self.navigationController?.pushViewController(CustomViewController(), animated: true)
这是弹出的代码:
self.navigationController?.popViewControllerAnimated(true)
我也遇到了类似的问题.我在我的类中添加了空的 deinit
方法并添加了断点:
I had similar problem. I added empty deinit
method to my class and added breakpoint:
deinit {
}
因此它从未被调用过.
一旦我在正文中添加一些代码,它就开始按预期工作:
As result it's never called.
As soon as I add some code to the body it started working as expected:
deinit {
print("deinit called")
}
所以请确保您的 deinit
方法不为空.
PS.我正在使用 Swift 2、Xcode 7.1
So be sure that your deinit
method isn't empty.
PS. I am using Swift 2, Xcode 7.1
这篇关于Deinit 从未调用过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!