Before starting my topic I shall said that I’ve already try to get from forums and wiki some information before posting.
I’m trying to make constructive topic, treated it as such.
Here is the list of same of the pages that I’ve check before asking:
http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Reference_Count_and_AutoReleasePool_in_Cocos2d-x
http://www.cocos2d-x.org/projects/cocos2d-x/wiki/How_to_optimise_memory_usage
http://www.cocos2d-x.org/boards/6/topics/4908
http://www.cocos2d-x.org/boards/6/topics/678
Situation :
I’ve been developing in Cocos2d-x for some months and now my cross platform game begin to grow.
I’m really worry about memory, special in device with low memory, and I searching for best approach.
I’m doing a very complex menu scene that has own graphics, images, sound, music, and so on.
From menu scene I’m switching to game that actual has its own graphics, images, sound, musics, etc.
Each scene will have really strong memory usage.
Questions
Q1 : Two big scenes and transitions
I’m switching scenes using transitions, my investigation so far is until the transitions is end both scenes are running at the same time. I believe they running in a render texture and them bill draw with the transitions effects on the screen.
Then I need to have enough memory to have both things running at the same time.
xxx = memory used by MenuScene
yyy = memory used by GameScene
zzz = memory used by transition effects (no really much)
Stage 1: MenuScene : running using xxx memory
Stage 2: MenuScene GameScene : running using xxx+yyy+zzz
Stage 3: GameScene : running using yyy memory
And approach to reduce impact could be instead to going from MenuScene to GameScene is to go trough and loading scene that how only basic elements, just a color background and some “loading” text.
Them I could:
xxx = memory used by MenuScene
yyy = memory used by GameScene
www = memory used by LoadingScene (really low)
zzz = memory used by transition effects (no really much)
Stage 1: MenuScene : running using xxx memory
Stage 2: MenuScene LoadingScene : running using xxx+www+zzz memory
Stage 3: LoadingScene GamingScene : running using www+yyy+zzz memory
Stage 4: GamingScene : running using yyy memory
So in conclusion :
xxx+www+zzz < xxx+yyy+zzz
www+yyy+zzz < xxx+yyy+zzz
Is this approach right? Any problem with it?
Q2 : When release items.
If I do the approach in the 1st question a important point is when actual release the scene layer so its contents are release. (And as well clear unused cache textures and unload sounds).
In that approach could be the right place ::onExit of the Scenes to actual :
purge cached data, remove unused textures, remove sounds?.
As far as I understood, using the pool when the layer is destroy (is this actually happen?) all elements will have decrease they reference count and them release.
So if a try to unload unused texture onExit,are really unused at that point?
So basically, shall in init load all things mandatory for my scene (including preload of sounds), and them release (or force release) onExit?
Q3 : Temporary objects
In the game sometime we must display temporary objects, for example a explosion graphic.
Then we could just use in the action sequence create for that, movement, fade out, just add a CCRemoveSelf.
In that case all memory used by that sprite is properly clear, isnt it?
Of course not the texture but is ok since will be reuse several times.
Q4 : Reuse Particles emitters
Sometime we use particle emiters for temporary effects, setup as been remove after used,I believe that will clear is content but I’ve some question about performance and pre-loading.
If y create the particle system loading from a plist, but this loading will be happeng each time I need to emitted the particles. (Could be several emitters at a time).
Could be a better approach to in the scene init load one particle emitter, but not attach to the layer.
Call to retain, so is persistence.
When I need to draw the particles, use copy() and add to the layer, as well set-up auto remove on finish.
onExit from the scene release the original emitter.
Is this approach correct?
Q5 : CCString and formating
In a game you may try to format a string for any giving reason in several places, as for example trying to update your player score.
I saw in many places that people uses CCString::createWithFormat and them just getCString().
So since those CCString are not attached to the layer I don’t now when actually they memory will be released.
So a bunch of new allocs are done and I dont know when are actually release.
I was thinking several approach for this issue, fist have singleTone CCString to actually initWithFormat when I need to update the text. But I believe that initWithFormat may as well create the necessary memory space for the text, so could not be the best approach.
I was thinking just to have a char[SOME_CONSTANT_LENGHT] and use sprintf to actually format my text.
What should be the best approach?
Final :
Thanks to anyone that has read this long topic and feel free to answer no only the question, anything relevant for the topic.