Search code examples
iosmemory-managementcocos2d-iphoneccsprite

Proper Memory Management for this line? (Cocos2D)


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!


Solution

  • 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