Search code examples
iosmemory-managementswiftsprite-kitskscene

PresentScene memory : Does removeAllChildren propagate?


I have a simple game with a menu scene and a game scene. When the game scene ends, it goes back to the menu scene, then to the game scene and so on.

All transitions are handled with self.view?.presentScene(Scene(size: self.view!.bounds.size)).

I also added this code in both the MenuScene and the GameScene :

override func willMoveFromView(view: SKView) {
    self.removeAllActions()
    self.removeAllChildren()
}

However, using the profiling instrument "Allocations" and "Leaks", I realized that the memory consumption keeps growing (only a little though) after each presentScene. There is no "Leak" detection.

Does removeAllChildren propagate to all nodes within nodes ? Or should I do manual removal of all children within children ?

Note : I am using XCode 6.1.1, iPhone Simulator iOS 8.1

Memory keeps increasing in the graph


Solution

  • Using the function deinit to log some println() and see if does deinit, I found that MenuScene was correctly deinitializes but not GameScene. I had to apply

    self.removeAllActions()
    self.removeAllChildren()
    

    to one of the main scene node's nodes.