cocos2d scene deallocation and ccb nodes

389 Views Asked by At

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 ?

1

There are 1 best solutions below

6
On

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.