Post

Replies

Boosts

Views

Activity

Reply to Tracking down a memory leak
Hi @Developer Tools Engineer, memory graph debugger can't capture leaks on my simple demo: I have 2 view controllers. View controller 1 is the root view controller of the app View controller 1 will use navigation controller to push to view controller 2 (which has retain cycle between itself and a closure) However, after I tap "Back" button in the navigation controller to go back to view controller 1 -> Memory graph debugger not show "ViewController2" as leak. Things to note here: This is leaks, not abandoned memory (since we can't not access to view controller 2) from anywhere else. So I wonder why Memory Graph Debugger doesn't work on this simple demo? This is the code of the sample project: class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() } @IBAction func didTapButton(_ sender: Any) { let vc2 = ViewController2() navigationController?.pushViewController(vc2, animated: true) } } final class ViewController2: UIViewController { private var callback: (() -> Void)? override func viewDidLoad() { super.viewDidLoad() callback = { self.view.backgroundColor = .red // retain cycle here } } }
Sep ’23