Game Development Reference
scene by passing self as a parameter to replaceScene . This will freeze or
crash your game!
Scenes and Memory
Keep in mind that when you replace one scene with another, the new scene is loaded
into memory before the old scene's memory is freed. This creates a short spike in
memory usage. Replacing scenes is always a crucial point where you can run into
memory warnings or straight into a crash related to not enough free memory. You
should test scene switching early and often when your app uses a lot of memory.
Note Cocos2d does a good job of cleaning up its own memory when you re-
place one scene with another. It removes all nodes, stops all actions, and un-
schedules all selectors. No extra work is required on your part. I mention this
because sometimes I come across code that makes explicit calls to the re-
moveAll and cleanup cocos2d methods. Remember, if in doubt, trust
cocos2d's memory management.
This issue becomes even more pronounced when you start using transitions. With
transitions, the new scene is created, the transition runs, and only after the transition
has done its job is the old scene removed from memory. It's good practice to add log
statements to your scene or to the layer that creates the scene:
self = [super init];
CCLOG(@"%@: %@", NSStringFromSelector(_cmd), self);