Understading memory collector: release + new

Hello,
I’ve been using this awesome library for a while and had a doubt about how the release / new mechanism works. For example for this code:

class A : public CCNode
{
// Some members & methods
}

class B : public CCNode
{
// Some members & methods
void func();
}

void B::func()
{

A a = new A;
this~~>addChild;

}
What happens when I call
B~~>removeAllChildren(true) // with cleanup = true
?

The A object is added to the B object, but not created using the release / retain / autorelease mechanism.
Does this provoke a memory leak?
Should I call delete getChildByTag; in the B destructor?

Thank you for your help! :smiley:

A a = new A;  // a.m_uRefCount = 1
this->addChild(a,0,0);   // b holds a, so a.m_uRefCount = 2
a->release();   // paring to new A 

So next time when you B->removeAllChildren(true), a.m_uRefCount will reduce to 0 and be released, you don’t need to call an extra delete.
You can refer to http://www.cocos2d-x.org/boards/6/topics/678?r=696

Thank you very much. That helped a lot.