Reputation: 3961
I have just recently migrated a cocos2d v1.x project to v2.x, and everything seemed to be ok. I then turned on ARC. But now, one of the CCLayer's dealloc never get called. During the conversion, most stuff in that method is gone, but just leaving an CCLog to indicate when the layer get deallocated. I am not sure what has gone wrong going from no-Arc to ARC. Various sources mentioned that there must be something else thats retaining it. This is strange since it deallocated alright b4 all these changes. I have yet to go through the specific of my code (that layer has lot of lot of code). But just want to see if there's any common pitfall regarding cocos2d v2.x + ARC.
Upvotes: 1
Views: 158
Reputation: 3961
Just fixed this. The reason why the cclayer got retained in the ARC case (after seemingly good conversion) but not before is I have declared instance variable
@interface SomeObject {
CCNode *_parent;
}
and I didnt have a @property defined for it.
I have made an assignment somewhere in the implementation. It seemed to be fine in no-ARC 'cos there may not be any retain on _parent. But after ARC, it seemed _parent is now a STRONG reference. And it is causing a parent-child style circular reference. I think one fix is to make it an unsafe_unretained. but i didnt bother since it's some old code i actually forgot to comment out. I got rid of this ivar. I think this could be a pitfall when trying to convert to ARC 1st time. it also mean declaring an ivar without @property is not a good practice and can bite like this when you convert old project.
Upvotes: 1