Xcode 内存图调试器不显示周期 [英] Xcode memory graph debugger not showing cycles

查看:25
本文介绍了Xcode 内存图调试器不显示周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 Xcode 内存图调试器来查找我们项目中的循环引用,我发现了其中的一些.

但是,我无法看到图表中的循环.只能通过检查代码.

例如我会看到...

<块引用>

ViewControllerA ---[parentViewController]---> ViewControllerB

但在代码中,它们的创建方式类似于 ...

class ViewControllerA: UIViewController {让 parentViewController: UIViewController}

还有……

class ViewControllerB: UIViewController {让 otherViewController: UIViewController!viewDidLoad() {...otherViewController = ViewControllerA(parentViewController: self)}}

显然这是一个循环引用.但是图中只显示了一个箭头.

有没有办法让图中的两个箭头都显示出来?

刚刚创建了一个示例...

新项目 - 单一视图 - 将 ViewController.swift 编辑为...

导入 UIKit类视图控制器:UIViewController {其他变量:ViewControllerB!覆盖 func viewDidLoad() {super.viewDidLoad()其他 = ViewControllerB(其他:自我)}}类 ViewControllerB: UIViewController {让其他: UIViewController初始化(其他:UIViewController){self.other = 其他super.init(nibName: nil, bundle: nil)}需要初始化?(编码器aDecoder:NSCoder){fatalError("init(coder:) 尚未实现")}}

内存图调试器...

专注于 ViewController...

关注 ViewControllerB...

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

像这样来自

解决方案

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

I have been using the Xcode memory graph debugger to find cyclic references in our project and I've found a few of them.

However, I haven't been able to see the cycles in the graph. Only by inspecting the code.

For instance I'll see ...

ViewControllerA ---[parentViewController]---> ViewControllerB

But in code they are created like ...

class ViewControllerA: UIViewController {
    let parentViewController: UIViewController
}

and...

class ViewControllerB: UIViewController {
    let otherViewController: UIViewController!

    viewDidLoad() {
        ...
        otherViewController = ViewControllerA(parentViewController: self)
    }
}

Clearly this is a cyclic reference. But it only shows one arrow in the graph.

Is there a way to make this show both arrows in the graph?

Just created an example...

New Project - Single view - Edit ViewController.swift to...

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")
    }
}

In Memory Graph Debugger...

Focus on ViewController...

Focus on ViewControllerB...

From these I can infer that there is a reference cycle. But there are tutorials on the web where it actually shows the cycle with arrows following a cycle around the objects...

Like this from Use your loaf

解决方案

Reference cycles only appear in the memory graph debugger for leaked objects. Because ViewController is referenced by UIWindow, it's not considered leaked, so the cycle between the view controllers isn't displayed.

这篇关于Xcode 内存图调试器不显示周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆