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 ?
What happens to the object created through this?
If you assign it to a retain property, it will get retained; so you need to release it explicitly. E.g.:
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 indealloc
.Contrast this to not using a property to keep a reference to the node object and add it directly to the node hierarchy:
in this case, you would not need doing any explicit release, since you are not retaining yourself the object.