【发布时间】:2018-02-26 12:44:03
【问题描述】:
我一直在使用 Xcode 内存图调试器来查找我们项目中的循环引用,并且我找到了其中的一些。
但是,我无法在图表中看到周期。仅通过检查代码。
例如我会看到...
ViewControllerA ---[parentViewController]---> ViewControllerB
但在代码中,它们的创建方式类似于 ...
class ViewControllerA: UIViewController {
let parentViewController: UIViewController
}
还有……
class ViewControllerB: UIViewController {
let otherViewController: UIViewController!
viewDidLoad() {
...
otherViewController = ViewControllerA(parentViewController: self)
}
}
显然这是一个循环引用。但它只在图中显示一个箭头。
有没有办法让它在图表中显示两个箭头?
刚刚创建了一个示例...
新项目 - 单一视图 - 编辑 ViewController.swift 到...
import UIKit
class ViewController: UIViewController {
var other: ViewControllerB!
override func viewDidLoad() {
super.viewDidLoad()
other = ViewControllerB(other: self)
}
}
class ViewControllerB: UIViewController {
let other: UIViewController
init(other: UIViewController) {
self.other = other
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
在内存图调试器中...
专注于 ViewController...
关注 ViewControllerB...
从这些我可以推断出有一个参考循环。但是网上有教程,它实际上显示了在对象周围循环后带有箭头的循环......
【问题讨论】:
标签: xcode memory-graph-debugger