memory leak?

Hi,

I just wanted to make sure that I was handling this correctly and not creating a memory leak. I read the wiki on reference counting but … guess I’m just not that confident still. Appreciate your thoughts.

I have an array of sprite pointers…

cocos2d::CCSprite* mSprites[6];
that are filled with random images in a load function (can be 1-6 unique images). In load each sprite is created and then added to the layer.

mSprites[i] = cocos2d::CCSprite::create(tfile.c_str()); mLayer->addChild(mSprites[i], i);

In my unload I just called
@
mLayer->removeAllChildren();@

Can I call load again with out creating a memory leak or do I have to do more to free up the sprites?

Thanks

I think you can call load again and you don’t have memory leak but i can be wrong :slight_smile: I thinks so because for all children you call release()

I think you still have to empty the array before loading again. Also, you might want to use CCArray instead of normal C++ arrays.

Just like Lance Gray said, you should use CCArray, and remember you have to call release() function from the CCArray inside your class destructor because you will have to retain it so you can use it anywhere in your class. But I suggest you to use std::vector, then inside your class destructor you could clear the vector.

That works too. I was hesitant at first worrying that clearing a vector doesn’t destroy CCObjects when you clear it then when I tried it, it was working fine.