TEST( Notifier, TestOfNotificationUseAfterRelease ) { Notifier notifier; TestClazzReleased* pReleasedNode = new TestClazzReleased( notifier ); pReleasedNode->init(); CCNode* pHolder = new CCNode(); pHolder->init(); notifier.addNotification( getNotificationTestUseAfterRelease(), {pHolder, &CCNode::removeAllChildren } ); EXPECT_EQ( 1u, pReleasedNode->retainCount() ); EXPECT_EQ( 1u, pHolder->retainCount() ); pHolder->addChild( pReleasedNode ); EXPECT_EQ( 2u, pReleasedNode->retainCount() ); EXPECT_EQ( 1u, pHolder->retainCount() ); pReleasedNode->release(); EXPECT_EQ( 1u, pReleasedNode->retainCount() ); EXPECT_EQ( 1u, pHolder->retainCount() ); //OLD: Now when we notify we have problem. We have use after release. //NEW: Now everything should work because we mark second notification as toRemove so we simply skip it :) notifier.notify( getNotificationTestUseAfterRelease() ); pHolder->release(); }
void Bug422Layer::check(CCNode* t) { CCArray *array = t->getChildren(); CCObject* pChild = NULL; CCARRAY_FOREACH(array, pChild) { CC_BREAK_IF(! pChild); CCNode* pNode = (CCNode*) pChild; CCLog("%p, rc: %d", pNode, pNode->retainCount()); check(pNode); }