Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So first of all, let me explain how cocos2d-x memory management work.</p> <p>Since cocos2d-x is related to cocos2d, the cocos2d-x team willing to using retain/release stuff like in object-c.</p> <p>Obviously, a CCObject will be hold in memory only if his retain value is larger than 0.</p> <p>Once you call the function release();, the retain value of this object will minus 1, and if it reached 0, the destructor will be called.</p> <p>Finally, the autorelase() function. What is it, for cocos2d-x, the core thread hold a CCArray in CCPoolManager::sharedPoolManager(). In each frame, all the object in this array will call release() once, and will be removed if the retain value == 0.</p> <p>So let's come in this case.</p> <p>I believe that the autorelease() is the reason why make you confused. When an object is created by new ClassName(), the retain == 1; But if it is called autorelease(), it still remain 1, but will be 0 in the next frame.</p> <p>That's why when you use this->matrix[0][0] = SomeClass::create(); the constructor, init and destructor will be called one by one, but remember, the destructor is called in the next frame not immediately after the init().</p> <p>So how to make these correct, there's many way to do this. Most easy way is : this->matrix[0][0] = SomeClass::create(); this->matrix[0][0]->retain();</p> <p>Besides that, I strongly recommend that using CC_SYNTHESIZE_RETAIN(varType, varName, funName) to define a value instead of ClassName* valueName in the headder file.</p> <p>And use set##funName(varType var) to set it instead of using valueName = ClassName::create().</p> <p>For more information, you can have a read on CC_SYNTHESIZE_RETAIN marco.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload