Memory management has me confused again —
In my .h file, I have:
@property (nonatomic,retain) NSMutableDictionary *properties;
In my .m, I have the following init method, which complains of a leak in Instruments on the self.properties line:
- (id) init {
self = [super init];
self.properties = [[NSMutableDictionary alloc] init];
return self;
}
It also complains of a leak if I don’t use the accessor.
Likewise, it leaks if I use this strategy:
NSMutableDictionary *temp = [[NSMutableDictionary alloc] init];
self.properties = temp;
[temp release];
And in dealloc I have:
self.properties = nil;
[properties release];
I thought I was following the rules, but this one is alluding me.
If your .h is defined like this:
The following are possible correct implementations of your .m:
or
It might be helpful to remember that
is the same as
Those 2 methods that are synthesized for you would look similar to the following: