title: How the closure remove the memory for view controller?
body: <p>I would like to know about memory management in the closure. </p>
  
  <p>for instance, we have a view controller that has a closure to finish. When I Check the reference count to the view controller it's showing the reference count 1.  </p>
  
  <p>When the memory will clear/remove for the dismissed view controller?   </p>
  
  <p>Here is my code. </p>
  
  <pre><code>class ViewController: UIViewController {
  
      @IBOutlet weak var buttonToHide: UIButton!
  
      override func viewDidLoad() {
          super.viewDidLoad()
          // Do any additional setup after loading the view.
      }
  
      @IBAction func showSecondViewController()  {
          guard let second  = self.storyboard?.instantiateViewController(withIdentifier: "second") else { return  }
          present(second, animated: true, completion: nil)
      }
  
  }
  
  
  
  class SecondViewControler: UIViewController {
  
      @IBOutlet weak var lbl:  UILabel!
  
      override func viewDidLoad() {
          super.viewDidLoad()
      }
  
      override func viewDidAppear(_ animated: Bool) {
          super.viewDidAppear(animated)
      }
  
      deinit {
          print("\(self) is being deinitialized") // still self object is there
          print(_getRetainCount(self)) // returning 1
      }
  
      @IBAction func dismissController()  {
          DispatchQueue.main.asyncAfter(deadline: .now() +  .seconds(6)) {
              self.lbl.text = "HHi"
              print("self reference : ",self.lbl.description)
          }
          self.dismiss(animated: true, completion: nil)
      }
  
      override func viewDidDisappear(_ animated: Bool) {
          super.viewDidAppear(animated)
          print("viewDidDisappear", self.lbl.description)
      }
  
  }
  </code></pre>