memory management - Cocos2D: What needs to be allocated? -


i should know can´t decide when allocate game objects when when don´t need to.

example: have pause button in game. button not allocated in way, put in input layer this: pausebutton = [ccsprite spritewithspriteframename:@"pause.png"];

i´ve done labels.

however, added character object game tutorial, this: [[[self alloc]initwithimage] autorelease]; (this line part of method)

well, how 1 decide if allocate game object or not? there practice or should allocate->autorelease add game?

actually 2 lines identical. spritewithspriteframename static function of ccsprite class. returns autorelease object.

initwithimage non-static need allocate first, since it's marked autorelease, behaves in same way.

my rule of thumb if there static functions available return auto-release objects, use them convenience sake. if remove autorelease second example, have manually call "release" on object destroy it. cannot call release on autorelease object, there may cases want destroy object (and not on scene change instance).

hope helps!


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -