0

I'm new to game development with SpriteKit and everything went ok so far, but cant really the memory management part.

I created a first UIViewController to act as a level selector, a second UIViewController in which a present the SKScene of the game. The problem appears when i go back from the SKScene to the level selector and none of the memory is released.

From the game SKScene, when the user pushes the back button to go to the level selector i post a notification which tells the second UIViewController to perform the segue.

//SKScene
[self removeAllActions];
[self removeAllChildren];
[self removeFromParent];

[[NSNotificationCenter defaultCenter]postNotificationName:@"toLevelSelector" object:nil userInfo:nil];

//Second UIViewController
- (void)toLevel:(NSNotification *)notif
{
    [self performSegueWithIdentifier:@"toLevelSelector" sender:self];
}

Can you help me get a better understanding on when and where should be the skview or the skscene released from memory ?

Macaret
  • 797
  • 9
  • 33
  • can you explain how you determined that the scene wasn't released? Do the two view controllers create different instances of SKView (not recommended)? – CodeSmile Oct 23 '14 at 11:36

1 Answers1

0

I think the memory is not released because you did not dismiss view controller that holds SpriteKit. When I first tried to make game that has menus in UIViewControllers and then button starts SpriteKit game, I experienced that closing game does not end timers, sounds, music, etc... Let's say you have UIViewController called MainMenuViewController and that it has a button that calls GameViewController in which you run SpriteKit Game. So in order to close your game completely, try to implement this method in your exit game button

[(GameViewcontroller *)self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
John Houston
  • 97
  • 2
  • 10