1

I am programming a game using scenekit that has different levels, that are different files (uiviewcontrollers) (level1.swift, level2.swift...) When you complete a level, you can replay it. What i have noticed, is when you start the game, it uses about 33 mb memory. Now when you press a replay button which presents the level 1 viewcontroller again, the game uses about 60 mb of memory.

So the question is, Is there a way i could somehow remove the level 1 when i present it again? Something like: Level1. RemoveFromMemory Self.presentViewController(level1)?

Pietari
  • 83
  • 4

1 Answers1

0

Those sounds like symptoms of a memory leak. You could cause this by keeping multiple strong references to the scene assets. You could also cause it by writing a retain cycle: parts of the scene hold strong references to each other, so even when you release the scene it can't let itself be deallocated.

Run your game using the Leaks Instrument. The WWDC videos on Instruments are helpful. And the Memory Graph Debugger in Xcode 8 will help you a ton.

Hal Mueller
  • 7,019
  • 2
  • 24
  • 42
  • Could this be a nstimer that runs a function every 5 seconds? – Pietari Sep 11 '16 at 06:05
  • Sure, if you never deactivate it and nil it out (using NSTimer in SceneKit is questionable design in the opinion of many btw). – Hal Mueller Sep 11 '16 at 06:11
  • How do you deactivate it? – Pietari Sep 11 '16 at 07:30
  • Read the class reference for NSTimer from start to finish. Then edit your question to include the code you're using and explain what you're doing. If you're still stuck (you won't be) I'll take a look. – Hal Mueller Sep 11 '16 at 07:48
  • This answer is worth a look too. I don't know if the SceneKit bug described still exists. http://stackoverflow.com/questions/32295206/scene-kit-memory-management-using-swift/34325822#34325822 – Hal Mueller Sep 12 '16 at 04:05