I am building an iOS game aimed for the new iOS 7 and Sprite Kit, using emitter nodes and physics to enhance gameplay. While developing the app, I ran into a serious problem: you create your scenes, nodes, effects, but when you are done and need to return to the main screen, how do you free up all the memory allocated by these resources?
Ideally ARC should free up everything and the application should get back to the memory consumption level it had before creating the scene, but this is not what happens.
I've added the following code, as the dealloc method of the view, which draws the scene and is responsible for removing everything upon getting closed (removed):
- (void) dealloc
{
if (scene != nil)
{
[scene setPaused:YES];
[scene removeAllActions];
[scene removeAllChildren];
scene = nil;
[((SKView *)sceneView) presentScene:nil];
sceneView = nil;
}
}
- sceneView is a UIView, which is the container of the scene
- scene is an extension of the SKScene class, creating all the SKSpriteNode objects
I would very much appreciate any help on this matter.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…