Deinit never called

前端 未结 13 1864
清歌不尽
清歌不尽 2020-11-30 03:51

I\'m creating a ViewController object an pushing it to a navigation controller. When the object is being popped from the stack - it is not being release and Deinit is not be

13条回答
  •  孤街浪徒
    2020-11-30 04:08

    I had the same issue when the NotificationCenter was holding a strong reference to the presented view controlled and thus it was never getting released. So I had to add [weak self] to the block like this:

    (in the viewDidLoad)

    NotificationCenter.default.addObserver(forName: .showFoo, object: nil, 
      queue: OperationQueue.main) { [weak self] (notification) in
        if let foo = notification.userInfo?["foo"] as? Foo {
                self?.afooButton!.setImage(UIImage(named: "foo"), for: .normal)
        }
    }
    

提交回复
热议问题