title: Deinit not called on a UIViewController, but Dealloc is
body: <p>It <a href="https://stackoverflow.com/questions/25497928/dealloc-in-swift">seems like the Swift equivalent of <code>dealloc</code> is <code>deinit</code></a>. However, when you attempt to define the method on a UIViewController, it doesn't behave as you would expect...</p>
  
  <p><strong>Setup</strong></p>
  
  <ol>
  <li>Create a new Single View project using Xcode 7.0, in either Swift or Objective-C.</li>
  <li>Add a "dismiss" button on the view controller that was created with the storyboard (I'll refer to this view controller as VC2; its class is ViewController).</li>
  <li>Add a new view controller and set it to be the initial view controller (VC1, class is nil). </li>
  <li>Add a "present" button to VC1 with a "Present Modally" segue to VC2.</li>
  <li>In VC2's code, put a breakpoint in <code>deinit</code> (Swift) or <code>dealloc</code> (Objective-C).</li>
  <li><p>In VC2, make the "dismiss" button's action do the following:</p>
  
  <pre><code>// Swift:
  presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
  
  // Objective-C:
  [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
  </code></pre></li>
  <li>Run the app and tap both buttons to first present VC2 and then dismiss it.</li>
  </ol>
  
  <p>Notice how in <strong>Objective-C</strong>, <strong>the <code>dealloc</code> breakpoint is hit</strong>.</p>
  
  <p>In <strong>Swift</strong>, on the other hand, <strong>the <code>deinit</code> breakpoint is never hit</strong>.</p>
  
  <p><strong>Why is <code>deinit</code> never called?</strong> Is this a bug or by design? </p>
  
  <p>If this is by design, where should I put clean up code to free up resources when the view controller will no longer be needed? (It can't be in <code>viewDidUnload</code> since that method is deprecated. It can't be in <code>viewDidDisappear</code> because something else might be holding a reference to it and will eventually show it again.)</p>
  
  <hr>
  
  <p>Note: If you attempt to define a <code>dealloc</code> method in Swift, you get the following error:</p>
  
  <blockquote>
    <p>Method 'dealloc()' with Objective-C selector 'dealloc' conflicts with deinitializer with the same Objective-C selector.</p>
  </blockquote>
  
  <p>If you have the Swift view controller inherit from an Objective-C controller, and you put a breakpoint in the Objective-C dealloc method, you will get the same buggy behavior defined above: the <code>deinit</code> will not be called, but the <code>dealloc</code> will be called.</p>
  
  <p>If you attempt to use Allocations to view the number of instances of the class in memory, both versions show the same thing: The <code># Persistent</code> is always 1, and the <code># Transient</code> increases each time you show the second view controller.</p>
  
  <p>Given the above setup, there should be no <a href="https://stackoverflow.com/questions/26958162/ios-how-to-check-if-uiviewcontrollers-are-unloading-swift">strong reference cycle</a> holding on to the view controller.</p>