It depends on how you're assigning it. If your assignment is directly to the ivar, like
myProperty = [[NSMutableArray alloc] init];
Then a single release in dealloc is adequate, because you have an expected retain count of 1 from the alloc.
On the other hand, if you have used a synthesized setter via either:
[self setMyProperty:[[NSMutableArray alloc] init]];
or
self.myProperty = [[NSMutableArray alloc] init];
then you have almost certainly leaked the object. You incremented the retain count twice (once via alloc
and once in the setter) and only decremented it once (in dealloc
).
Best IMO is to use the setter and the autorelease pool:
self.myProperty = [[[NSMutableArray alloc] init] autorelease];
Here the alloc
is balanced with a local autorelease, and the setter`s retain is balanced with the dealloc release.
While that approach involves two extra methods (the setter method and the autorelease call), it ensures that any retained values that were formerly set in the the property are release
d as necessary (in the setter method).