title: Deallocate SKScene after modal transition
body: <p>I have been creating a game in sprite kit using swift and have encountered a problem. I have two view controllers, each with one scene and one transitions to the other modally. This all works perfectly first time round, but then when i return to the first view controller and then go to the second again, i have using double the memory. This gives me the impression that nothing is being deallocated, but the objects are rather reallocated every time I transition to the scene. I ran the app in instruments and got the same result. In the below image i moved from one scene to the next, and then back to the first one again and yet it appears to reallocate the first scene and yet not clear any memory. As the dealloc method is unused now, i don't see how i can fix this. I will post the code to the first view controller below so you can have a look at it. Thanks a lot.</p>
  
  <p><img src="https://i.stack.imgur.com/zKohu.png" alt="Instument&#39;s recordings"></p>
  
  <pre><code>import UIKit
  import SpriteKit
  
  class SelectionViewController: UIViewController {
  
  var selectionScene:SelectionScene?
  var currentRocketName = ""
  
  @IBOutlet var playButton: UIButton
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      if let selectionScene = SelectionScene.unarchiveFromFile("SelectionScene") as? SelectionScene {
  
          // Configure the view.
          let skView = self.view as SKView
          skView.showsFPS = true
          skView.showsNodeCount = true
          skView.multipleTouchEnabled = false
  
          /* Sprite Kit applies additional optimizations to improve rendering performance */
          skView.ignoresSiblingOrder = true
  
          /* Set the scale mode to scale to fit the window */
          selectionScene.scaleMode = .ResizeFill
          selectionScene.viewController = self
  
          skView.presentScene(selectionScene)
  
          NSNotificationCenter.defaultCenter().addObserver(selectionScene, selector: "spinnerChanged", name: "spinnerValueChanged", object: nil)
          NSNotificationCenter.defaultCenter().addObserver(selectionScene, selector: "productBought", name: "ProductBought", object: nil);
          NSNotificationCenter.defaultCenter().addObserver(selectionScene, selector: "manageErrorInPurchase", name: "ErrorOccured", object: nil)
  
      }
  }
  
  override func shouldAutorotate() -&gt; Bool {
      return true
  }
  
  override func viewDidAppear(animated: Bool)  {
  }
  
  @IBAction func playButtonPressed(sender: UIButton) {
      self.performSegueWithIdentifier("moveToGame", sender: nil)
  }
  
  override func prefersStatusBarHidden() -&gt; Bool {
      return true
  }
  
  override func supportedInterfaceOrientations() -&gt; Int {
      if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
          return Int(UIInterfaceOrientationMask.AllButUpsideDown.toRaw())
      } else {
          return Int(UIInterfaceOrientationMask.All.toRaw())
      }
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Release any cached data, images, etc that aren't in use.
  }
  
  override func viewDidUnload() {
      NSNotificationCenter.defaultCenter().removeObserver(selectionScene)
  }
  
  override func viewDidDisappear(animated: Bool) {
      NSNotificationCenter.defaultCenter().removeObserver(selectionScene)
  }
  
  override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
      if segue.identifier == "moveToGame" {
          let destController = segue.destinationViewController as GameViewController
          destController.rocketTexture = SKTexture(imageNamed: self.currentRocketName)
      }
  }
  
  }
  </code></pre>
  
  <p>Both <code>selectionScene</code> and <code>currentRocketName</code> are passed to the viewController as soon as they are loaded into the view</p>