【问题标题】:Xcode memory graph debugger not showing cyclesXcode 内存图调试器不显示周期
【发布时间】: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...

从这些我可以推断出有一个参考循环。但是网上有教程,它实际上显示了在对象周围循环后带有箭头的循环......

点赞Use your loaf

【问题讨论】:

    标签: xcode memory-graph-debugger


    【解决方案1】:

    引用循环仅出现在内存图调试器中用于泄漏对象。因为 ViewController 被 UIWindow 引用,所以不认为是泄露的,所以不会显示视图控制器之间的循环。

    【讨论】:

    • 明天我得再看看。我想我能够建立一个带有泄漏对象的项目,但仍然没有以这种方式显示。如果可以的话会回复你的。哈哈
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-15
    • 2017-12-31
    • 2010-11-15
    • 2011-02-16
    • 2013-10-24
    • 2011-04-12
    • 1970-01-01
    相关资源
    最近更新 更多