diff --git a/cocos2dx/cocoa/CCSet.cpp b/cocos2dx/cocoa/CCSet.cpp index 0078cfb5d9..8ab306af56 100644 --- a/cocos2dx/cocoa/CCSet.cpp +++ b/cocos2dx/cocoa/CCSet.cpp @@ -52,18 +52,7 @@ CCSet::CCSet(const CCSet &rSetObject) CCSet::~CCSet(void) { - // call release() of elements - CCSetIterator iter; - for (iter = m_pSet->begin(); iter != m_pSet->end(); ++iter) - { - if (! (*iter)) - { - break; - } - - (*iter)->release(); - } - + removeAllObjects(); CC_SAFE_DELETE(m_pSet); } @@ -98,20 +87,16 @@ void CCSet::removeObject(CCObject *pObject) void CCSet::removeAllObjects() { - if (!m_pSet || m_pSet->empty()) - { - return; - } + CCSetIterator it; + for (it = m_pSet->begin(); it != m_pSet->end(); ++it) + { + if (! (*it)) + { + break; + } - CCSetIterator it; - - for( it = m_pSet->begin(); it != m_pSet->end(); ++it) - { - if(*it) - { - removeObject(*it); - } - } + (*it)->release(); + } } bool CCSet::containsObject(CCObject *pObject)