How to list all live (non-deallocated) UIViewContr

2019-08-17 03:57发布

Some UIViewControllers do not seem to get deallocated.

What's the best way to list and identify all live (non-deallocated) UIViewControllers?

2条回答
贼婆χ
2楼-- · 2019-08-17 04:45

Run app in debugger and use "Debug memory graph" button debug memory graph and see the list of the view controllers in the panel on the left. If you happened to follow the convention of including ViewController in the name of your view controllers (e.g. MainViewController, DetailsViewController, etc.), you can filter the list of objects listed in the left panel by typing ViewController in the "filter" text box at the bottom of the left panel:

enter image description here

In this example, I also clicked on my third view controller, and I can see it was presented by the second one, which was presented by the first one.


The other approach is to use the "view debugger" enter image description here, but that only shows the view controllers that are currently present in the active view controller hierarchy and may not show view controllers whose views are not currently visible because the view controller presented another view controller modally.

查看更多
forever°为你锁心
3楼-- · 2019-08-17 04:56

In addition to Rob's answer, if you want to see them initialized and deinitialized in real time you can print to console.

class Random32ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        print("32 did load")
    }

    deinit {
        print("32 did deinit")
    }

}

You can do this method on all class types beyond just view controllers.

查看更多
登录 后发表回答