0

So there is a partial answer to this question for Obj. C. and I am just asking the mechanics of the same idea within Swift. Furthermore I want to compare and contrast switching ViewControllers and switching scenes as a way of switching between a game and its MainMenu. Presenting a scene in SpriteKit without discarding the previous?

In the above section, the author said that scenes are completely discarded when I present a new scene in that ViewController, is this true in spritekit/swift? What I am doing is I have a couple of scenes (GameScene, MainMenuScene, OptionsScene, etc.) That I am constantly switching between as a way of switching views entirely. Will this delete all data associated with that instance of GameScene? I don't want any remnants of that data slowing down my game over time. Furthermore, some people recommend switching ViewControllers instead of scenes for the idea of MainMenu, etc. What are the positives and negatives to each method?

Community
  • 1
  • 1
Brennan Adler
  • 895
  • 2
  • 8
  • 18
  • I use a ViewController for a help screen in my game, I present it from the same view controller that presents my SKScene. When I pop it the SKScene just picks up from where it left off. I'd say if you can get away with using a VC, do it – Toby May 08 '15 at 00:44

1 Answers1

1

Yes it will delete the data associated with the scene when you present a new scene unless you have some kind of strong reference cycle. If you have a strong reference cycle, your scene and associated objects stay in memory and you have no way of accessing them. Not good.

One easy way to tell if your scene is being removed from memory is to put a deinit method inside the scene, and print something inside of that. If deinit is called, then your scene was removed.

If you want to see exactly what objects exist within your game at different points you can use the Allocations instrument. You can find it under XCode > Open Developer Tool > Instruments

hamobi
  • 7,940
  • 4
  • 35
  • 64