I am using Cocos Builder to create scenes using sceneWithNodeGraphFromFile:owner:. Now I have doubts about whether it's better, on iOS, to save some memory or CPU cycles. In other words I have two options:

First, I could do lazy initialization of scenes without removing them from memory, like this:

- (CCScene*) myScene
        _myScene= [CCBReader sceneWithNodeGraphFromFile: @"MyFile.ccbi"];
    return _myScene;

Then I always call self.myScene and I possibly set _myScene to nil if the app receives a memory warning. I never remove a scene from the director, I just push without cleaning.

Or, I could initialize a new scene every time. I'd call sceneWithNodeGraphFromFile:owner: every time that I need to push a scene, popping and cleaning it from the director and creating it again if I need it.

Which should I prefer and why?

  • \$\begingroup\$ I can see no reason to not keep as much as possible in memory. As long as the memory is available: why not? Then again, I am not an experienced Cocos2D programmer :-) \$\endgroup\$
    – parasietje
    Feb 14, 2014 at 16:40

1 Answer 1


I'd advise that you prefer consuming memory to preserve CPU where possible. Keep scenes in memory as long as you can (or need to) to ensure a smooth transition experience for users. In other words, go with your first ("lazy loading") approach.

By preserving the scene, you also allow yourself to preserve any scene state as well, which means you can (if you want) return to them in the same state the user left them in, which can be desirable.

You should still obey iOS's requests to purge non-critical resources, so you'll want a lazy approach anyhow. Plus, especially on a mobile platform, high CPU utilization is likely to negatively impact battery life more than high memory utilization.

  • \$\begingroup\$ As a consumer (and iPad 2 user), I'd like to add, though, that I personally do respect apps with a low memory footprint. iOS7 takes up more RAM than previous versions, and as such I can generally only multitask between 2 open apps at once. \$\endgroup\$
    – Fault
    Mar 5, 2014 at 17:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .