title: Release UIViewController in Swift
body: <p>I've written a game in Swift where I'm running into memory problems.
  This is because I create a new UIViewController for every new level.
  I would like to release this UIViewController.
  I stumbled across the following solution on Stackoverflow:</p>
  
  <pre><code>GameViewController* gvc = [[GameViewController alloc] init];
  [self.navigationController pushViewController:gvc animated:YES];
  [gvc release];
  </code></pre>
  
  <p>Can anyone help me getting the Swift equivalent. I have</p>
  
  <pre><code>let gvc = (name: storyboardName, bundle: nil).instantiateViewControllerWithIdentifier(gvcStoryboardIdentifier) as GameViewController
  gvc. ... //setting a few properties
  
  
  presentViewController(gvc, animated: true, completion: nil)
  
  //how do I release the current controller that is presenting the new ViewController?
  </code></pre>
  
  <p>EDIT: Here's the code</p>
  
  <pre><code>class GameViewController: UIViewController, NavigationDelegate   
  {
        var currentLevel = 0
  var remainingLives = totalAmountOfLives
  weak var scene : GameScene!
  
  override func viewDidLoad() {
  super.viewDidLoad()
  
      scene = GameScene.unarchiveFromFile("GameScene") as GameScene
  
  
      // Configure the view.
      let skView = self.view as SKView
      //skView.showsFPS = true
      //skView.showsNodeCount = true
  
      scene.navigationDelegate = self
      scene.level = currentLevel
      scene.remainingLives = remainingLives
      /* Sprite Kit applies additional optimizations to improve rendering performance */
      skView.ignoresSiblingOrder = true
  
      /* Set the scale mode to scale to fit the window */
      scene.scaleMode = .AspectFill
      skView.presentScene(scene)  
  
  }
  
        func showWinner(time: NSTimeInterval)
          {
  
          scene.removeFromParent() //trying to release some space
          scene = nil
          ScoreSaver.addToScore(time) //add the time needed to complete this level
  
          if(currentLevel + 1 == amountLevels) //all levels have been completed
          {
              weak var wonAllLevelsController = (UIStoryboard(name: storyboardName, bundle: nil).instantiateViewControllerWithIdentifier(wonAllLevelsIdentifier) as WonAllLevelsViewController)
  
  
              presentViewController(wonAllLevelsController!, animated: true, completion: nil)
              self.removeFromParentViewController() //save memory
  
          }
          else
          {
              weak var wonGameController = (UIStoryboard(name: storyboardName, bundle: nil).instantiateViewControllerWithIdentifier(wonGameControllerIdentifier) as WonGameController)
              wonGameController!.elapsedTime = time
              wonGameController!.level = currentLevel
              wonGameController!.remainingLives = remainingLives
  
  
  
              presentViewController(wonGameController!, animated: true, completion: nil)
              self.removeFromParentViewController()
          }
  </code></pre>
  
  <p>In the WonGameViewController I have a button that guides the user to the next level.</p>
  
  <pre><code>class WonGameViewController{
  
  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
  
      if segue.identifier == nextLevelSegueIdentifier {
  
  
  
  
              weak var gameViewController = (segue.destinationViewController as GameViewController)
              gameViewController!.currentLevel = ++level % amountLevels //advance to the next level
              gameViewController!.remainingLives = remainingLives
              self.removeFromParentViewController()
  
  
  
      }
  
  }
  }
  </code></pre>
  
  <p>Within the SKScene CPU intensive operations are performed. Whenever I advance to the next level the consumed memory increases by about 2MB. Sometimes (I don't know when), it suddenly increases by 40MB </p>