I was quickly going over a large project looking for memory leaks, and came across a @property (nonatomic, retain) without a corresponding release in dealloc. Oops, quick fix, I think.
After a later crash, I look closer and the setFoo method is overriden, and the value is being retained but not by the ivar – for the sake of this question, assume it’s being put into an NSDictionary.
(OK, if you don’t want to assume that – the set value is actually a CCSprite in cocos2d, setNormalSprite, and it is being added as a child, thus retained, but simply assigned to the ivar:
- (void)setNormalSprite:(CCSprite *)sprite
{
if (normalSprite) {
[self removeChild:normalSprite cleanup:YES];
normalSprite = nil;
}
normalSprite = sprite;
[self addChild:normalSprite];
(...omitted...)
}
)
What is the correct keyword for a value whose setter causes the retain count to increase, but not because the ivar it’s associated with is retained?
retain(orstrongin ARC world) is correct in your case because you’re adding yourCSSpriteobject into another collection that retains the object.You should set the
@propertyto@dynamicin your@implementationtoo if you are not actually using an instance variable to store the object.