0

I have a simple CCScene containing only one node created from a CocosBuilder template with [CCBReader nodeGraphWithFile:] method.

So far, I did not release the ccb node in the dealloc method of the scene because I expected it to be autoreleased. But in the allocation profiler, I noticed that there is a memory leak if I push/pop the scene several times in the CCDirector.

This memory leak disappears if I actually release the node in the scene's dealloc method.

Why do I need to release the node though I didn't retain/init it ? Is there something I misunderstood ?

sdabet
  • 18,360
  • 11
  • 89
  • 158

1 Answers1

0

What happens to the object created through this?

[CCBReader nodeGraphWithFile:]

If you assign it to a retain property, it will get retained; so you need to release it explicitly. E.g.:

self.nodeGraph = [CCBReader nodeGraphWithFile:...];

if nodeGraph is declared as a retain property, the autoreleased object created in [CCBReader nodeGraphWithFile:] will get retained by the property and you will need to release it in dealloc.

Contrast this to not using a property to keep a reference to the node object and add it directly to the node hierarchy:

[self addChildNode:[CCBReader nodeGraphWithFile:...]];

in this case, you would not need doing any explicit release, since you are not retaining yourself the object.

sergio
  • 68,819
  • 11
  • 102
  • 123
  • I do not assign it to a property. I just add it to the scene via `[self addChildNode:[CCBReader nodeGraphWithFile:...]];`. That's why I'm confused – sdabet Jan 15 '13 at 08:51
  • so, which object are you sending the release to in the `dealloc` method? – sergio Jan 15 '13 at 08:52
  • `[[self.children objectAtIndex:0] release]` – sdabet Jan 15 '13 at 08:56
  • that´s no good... it is pretty clear that a `release` is missing, otherwise sending it doubly would cause a crash. either cocos2d is not releasing its children (odd) or CocosBuilder is unduly retaining it too much... give a look at `CCBReader` sources... – sergio Jan 15 '13 at 09:04
  • Yes that makes sense. Actually I'm not sure I use the latest version of CCBReader. I'll let you know if I find the trick. Thanks anyway – sdabet Jan 15 '13 at 09:07
  • 1
    It seems like the problem is cyclic retain cycle between the node and an animationManager. Someone has created an issue here: https://github.com/cocos2d/CocosBuilder/issues/190 – jdmunro Jan 16 '13 at 08:24