I am using double pointer for the CCSprite. For the pointer to pointer I am doing new and for then creating then using cocos2d usual method create How should I delete the double pointer in following case
CCSprite **mCBg;
mCBg = new CCSprite*[mNumberBackgound];
//for loop for creating sprites
mCBgLayer[i]= CCSprite::create("Sprites/level1.png");
Since Create automatically adds to the memory pool
What about the Objects created using 'new' how to delete them in destructor
if(mCBg)
{
CC_SAFE_DELETE_ARRAY(mCBgLayer);
}
If I do this I get crash in destructor Please give answer with explanation. So i can understand the memory management of cocos2d-x
Cocos2d-x use Reference Count
and AutoReleasePool
to manage memory.
The function CCSprite::create()
's implementation used autorelease()
.You do not need to release the memory, or the reference count will be smaller than 0;More detail see:
http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Reference_Count_and_AutoReleasePool_in_Cocos2d-x