0

It appears that when I call replaceScene, the spriteBatchNodes in my scene are not released. Each time I replace the scene, the "living" count goes up by one.

Each of the objects stored in the spriteBatchNode, is not just a CCSprite - It is a class derived from CCSprite with additional behavior.

What could cause the spriteBatchNode to not be released? None of the nodes I added to the spriteBatchNode are released either.

I unschedule all the selectors that are running on the nodes that are part of the spritebatchnode.

xcoder
  • 967
  • 2
  • 11
  • 24

1 Answers1

1

Most likely you have encountered a retain cycle. At least one of the nodes is still held on, so the sprite batch node isn't released.

Particularly common whenever you store node objects in additional custom collections (arrays, dictionaries, etc.). To be sure that Cocos2D can correctly release its memory, you will want to release those collections in the -(void) cleanup method rather than -(void) dealloc.

Community
  • 1
  • 1
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • You're right. For some reason, releasing the array containing references to CCSpriteBatchNode's did not reduce their retain count. I had to do [ removeAllObjects]. – xcoder Nov 30 '11 at 05:22
  • Also make sure your CCSprite and CCSpriteBatchNode's properties have assign instead of retain since all CCNodes are autoreleased. – Chewie The Chorkie Mar 03 '14 at 16:51