title: How to change ViewController to avoid memory leak
body: <p>I'm making game app that you can play 1~30 stages. When you proceed to next stage, I use this code</p>
  
  <pre><code>        var stageViewController: StageBaseViewController?
  
          switch stageNumber {
          case 1:
              stageViewController = Stage02Controller()
          case 2:
              stageViewController = Stage03Controller()
          case 3:
              stageViewController = Stage04Controller()  
          ...          
          case 29:
              stageViewController = Stage30Controller()
          default:
              print("error: unknown stage number.")
          }
          self.navigationController?.pushViewController(stageViewController!, animated: true)
  </code></pre>
  
  <p>But if you play some stages in a row, memory leak is caused. 
  How can I avoid this problem?</p>
  
  <p>*UPDATE</p>
  
  <p>The ViewController transition of this app is </p>
  
  <pre><code>A &lt; B &lt; C(gamestage)
  </code></pre>
  
  <p>And I tried to set ViewControllers like this</p>
  
  <pre><code>self.navigationController?.setViewControllers([aVC, bVC, cVC], animated: true)
  </code></pre>
  
  <p>But then old cVC's deinit didn't work. So I tried to remove old VC by this code</p>
  
  <pre><code>self.navigationController?.viewControllers.removeLast()
  </code></pre>
  
  <p>But self.navigationController?.viewControllers was nil.</p>
  
  <p>When I set 3 VCs deinit wasn't called so memory was increased.
  But set only 1 VC (cVC), deinit was called.
  How can I solve this problem?</p>