I have a property that has (nonatomic, assign) as attributes.
In a method, I then am retaining that variable then releasing it a line after.
Static analyzer is giving warning that incorrect decrement of the reference count of object....
Can I not do this
@property (nonatomic, assign) Class *iVar;
[self.iVar retain];
[self.iVar removeFromSuperview];
[self insertSubview:self.iVar atIndex:self.iVar.index];
[self.iVar release];
Since the retain and release both happen in the same method, you might want to copy the property to a local variable and then work with that:
That at least provides some protection in case the “some stuff” part happens to modify
self.interestingView. And it’ll probably satisfy the static analyzer, too.In general, I would avoid retaining/releasing variables that back properties outside the accessors for those properties, except for a few well defined situations such as
-dealloc. Similarly, avoid directly retaining/releasing the result of a property access, as in[self.foo retain]. If that property is changed before you get to the release, you end up with both a leak and, later, an over-release.