SpriteKit presentScene() Memory Leak

840 views Asked by At

I have a game with a Menu Scene and a Game Scene. In the Menu Scene I start the Game with:

let transition = SKTransition.fadeWithDuration(1)
let scene = GameScene(size: self.scene!.size)
scene.scaleMode = self.scaleMode
self.view!.presentScene(scene, transition: transition)

When the game is over I use the following code in the Game Scene to get back to the Menu Scene:

let transition = SKTransition.fadeWithDuration(1)
let scene = MenuScene(size: self.scene!.size)
scene.scaleMode = self.scaleMode

self.view!.presentScene(scene, transition: transition)

So far so simple. But with every transition the memory consumption increases. Is there a possibility to avoid this? For example reuse the Menu Scene?

enter image description here

This is how I load the first MenuScene in the GameViewController:

override func viewWillLayoutSubviews() {

    let skView = self.view as! SKView
    skView.showsFPS = true
    skView.ignoresSiblingOrder = true

    var scene = MenuScene(size: skView.bounds.size)
    scene.scaleMode = SKSceneScaleMode.AspectFill
    skView.presentScene(scene)   
}
0

There are 0 answers