都說cocos2d中使用addChild()時引用計數加一,請問具體在哪兒?`void Node::addChild(Node *child, int zOrder, int tag)
{
CCASSERT( child != nullptr, "Argument must be non-nil");
CCASSERT( child->_parent == nullptr, "child already added. It can't be added again");
if (_children.empty())
{
this->childrenAlloc();
}
this->insertChild(child, zOrder);
#if CC_USE_PHYSICS
if (child->getPhysicsBody() != nullptr)
{
child->getPhysicsBody()->setPosition(this->convertToWorldSpace(child->getPosition()));
}
for (Node* node = this->getParent(); node != nullptr; node = node->getParent())
{
if (dynamic_cast<Scene*>(node) != nullptr)
{
(dynamic_cast<Scene*>(node))->addChildToPhysicsWorld(child);
break;
}
}
#endif
child->_tag = tag;
child->setParent(this);
child->setOrderOfArrival(s_globalOrderOfArrival++);
if( _running )
{
child->onEnter();
// prevent onEnterTransitionDidFinish to be called twice when a node is added in onEnter
if (_isTransitionFinished) {
child->onEnterTransitionDidFinish();
}
}
if (_cascadeColorEnabled)
{
updateCascadeColor();
}
if (_cascadeOpacityEnabled)
{
updateCascadeOpacity();
}
}
`
進入this->insertChild(child, zOrder);
_children.pushBack(child);
再進入
void pushBack(T object)
就可以看到了
{
CCASSERT(object != nullptr, "The object should not be nullptr");
_data.push_back( object );
//addChild的引用計數加一在這
object->retain();
}``