How to correctly dismiss a UINavigationController that's presented as a modal? : <p>In my <code>TabBarViewController</code>, I create a UINavigationController and present it as a modal.</p>

<pre><code>var navController =  UINavigationController()
let messageVC = self.storyboard?.instantiateViewControllerWithIdentifier("MessagesViewController") as! MessagesViewController
self.presentViewController(self.navController, animated: false, completion: nil)
self.navController.pushViewController(messageVC, animated: false)
</code></pre>

<p>Inside my <code>MessageViewController</code>, this is how I want to dismiss it:</p>

<pre><code>func swipedRightAndUserWantsToDismiss(){
    if self == self.navigationController?.viewControllers[0] {
        self.dismissViewControllerAnimated(true, completion: nil) //doesn't deinit
    }else{
        self.navigationController?.popViewControllerAnimated(true) //deinits correctly
    }
}

deinit{
    print("Deinit MessagesViewController")
}
</code></pre>

<p>The problem is that when I get to the root View Controller and try to dismiss both the child and the UINavigationController, my <code>MessagesViewController</code> deinit does not get called.  Something's holding on to it -- most likely UINavigationController</p>
