Properly deleting CCArray issues

Properly deleting CCArray issues
0.0 0


I’m getting some heap access errors and I think it’s related to the destruction of my array.

I did a test with an array of objects, and just a single object itself, and it seems when I use array~~>release the destructor is never called on it’s contents. I guessing this is causing my heap problem because these objects contain references to b2Bodies and something funky’s going on.
Is simply calling array~~>release() not the correct way to dispose of an array and its contents?


Calling release() won’t dispose any objects immediately. It just decreases ref-count by one, and if ref-count is zero then it will be delete (destructor function called).
Make sure that your children in CCArray are not added somewhere else as their ref-count is not yet low enough to get dispose at that time.


Thanks! ya I didn’t realize that when a CCObject gets added to an array it +1s the ref count.

I just quickly ran through the array and released each object one time so the array release destroyed them all.