Some Question About Cocos2d-x Auto Memory Management

Some Question About Cocos2d-x Auto Memory Management
0.0 0


A sample Layer Class :

class HelloWorld: public CCLayer{
CCArray* arr;
arr = 0;

    bool init(){
                   return false;
           arr = CCArray::create();
           arr->retain(); **//position One  !!!!!!!!!!!**
           CCSprite* s = CCSripte::create("hello.png");

    void update(float dt){
           CCSprite* s = (CCSprite*)arr->objectAtIndex(0);
             s->setPosition(ccp(100, 100));


Please pay attention CCArray pointer arr.

You know,here must be invoke function “retain” at “position One” in the code to ensure pointer “arr” not be automatically released after a drawing cycle,

My question :

At Code “position One” after invoked “retain”, arr->m_uReference equals 2 (This results can get at the source code),
and the pointer “arr” was putted in the autoReleasePool

after a drawing cycle,“CCPoolManager” will invoke the “pop” function to execute “release” on all of the object in autoReleasePool

So, when “pop” function end, arr->m_uReference = 1;

and the “retain” function will never be execute on pointer “arr” in drawing cycle.

In this case, when after another drawing cycle and the “pop” function invoked, pointer “arr” was auto released, right ???

this is my question, why the pointer “arr” was not released ?

thank you for your help!