I’ve a NSMutableArray in AppDelegate
I’m using property (nonatomic,retain)
and synthesizing it
again in didfinishlaunch allocating it using [[nsmutablearray alloc]init];
So, my doubt is if I’m releasing it in deallloc using release method.
is it released properly?
or still retain count is there.
if I’m doing wrong kindly provide a proper solution.
It depends on how you’re assigning it. If your assignment is directly to the ivar, like
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:
or
then you have almost certainly leaked the object. You incremented the retain count twice (once via
allocand once in the setter) and only decremented it once (indealloc).Best IMO is to use the setter and the autorelease pool:
Here the
allocis 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
released as necessary (in the setter method).