Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
{
    if(!_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?

share|improve this question
    
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 :-) –  parasietje Feb 14 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.

share|improve this answer
    
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. –  Fault Mar 5 at 17:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.