Reputation: 12444
I am getting the following line as a leak in Xcode:
someSprite = [[CCSprite alloc] initWithFile:(NSString*)obj];
I know that I do alloc it there but I thought Cocos2D handled all of the memory management. Anyway how should I properly handle that line in order for there to not be a leak?
Should I simply use autorelease or is there more to it?
Thanks!
Upvotes: 0
Views: 132
Reputation: 10860
usually, it is more preferable to use static constructors that return autoreleased objects. For your case it will be
[CCSprite spriteWithFile:(NSString*)obj];
it will be retained when you add it to any parent
Upvotes: 1
Reputation: 9590
Cocos2D does not handle memory for you. However, I think you can use Automatic Reference Counting (ARC) to get rid of having to handle memory yourself. You then have use Cocos2d as a static library since cocos2d does not support ARC.
If you want to solve your problem without ARC just insert a autorelease. If it is a instance variable, release it in your dealloc method instead.
Upvotes: 2