0
votes

In my app, I have 3 different subclasses of SKScene for my menu, game, and game over screens. When the player hits an obstacle during the game, I present a new game over scene using:

EndGame *endGame = [[EndGame alloc] initWithSize:[UIScreen mainScreen].bounds.size];
SKView *spriteView = (SKView *)self.view;
[spriteView presentScene:endGame];

However, my gameScene is still running in the background (I can tell by printing a message in the update method). How can I make sure to deallocate the instance of the gameScene when I present the game over scene?

Currently, when I move between scenes my memory usage slowly increments.

1
are you retaining the scene somewhere as a strong property?rakeshbs
I have no idea what that means, so probably not.Luigi Mangione
Oh, no I never did that.Luigi Mangione
based on what you posted it should work.. there might be something else you're doing. why not try it on a stripped down project and see if you get the same result?hamobi
After trying a stripped down project, I found the problem. The update method did stop when I moved from the view. When I said earlier that I was using the update method, when I was actually using a custom timer to run my physics. I assumed this timer would automatically be invalidated when I moved from the view, but for some reason it kept running in the background. All I had to do was invalidate the timer before moving from the view. Thanks!Luigi Mangione

1 Answers

0
votes

Although you find the solution to your answer, I had something similar.

I have a navigationController which shows a MainViewController from which you can go to the GameViewController (with SKScene). After a 'game over' I would pop back to the MainViewController, however, my scene (in GameViewController) was still running in the background. I checked by printing the TimeInterval in the update() function.

What I ended up doing was, in my viewDidDisappear, i did a

skView.presentScene(nil)

This removed the scene in my case and freed up any memory it was using.