void CCNode::removeAllChildrenWithCleanup(bool cleanup) { // not using detachChild improves speed here if ( m_pChildren && m_pChildren->count() > 0 ) { CCNode * pNode; CCMutableArray<CCNode*>::CCMutableArrayIterator it; for ( it = m_pChildren->begin(); it!= m_pChildren->end(); it++ ) { pNode = *it; if (pNode) { // IMPORTANT: // -1st do onExit // -2nd cleanup if(m_bIsRunning) { pNode->onExit(); } if (cleanup) { pNode->cleanup(); } // set parent nil at the end pNode->setParent(NULL); } } m_pChildren->removeAllObjects(); } }