I'm going to manually manage the memory of the NSMutableDictionay, without using autorelease. And every object in the mutableDictonary is a NSArray, every time I add one array in the mutableDictionary, I'm going to use
NSArray *newArray = [[NSArray arrayWithArray:anArray] retain]
[mutableDict setObject:newArray forKey:@"aKey"];
question is, how can I ganrantee that there's no leak of memory? It is good that I directly use [mutableDict release] in the dealloc? does the retainCount of mutableDict equals to the sum of all the retainCounts of its objects(those retained arrays)?
retain
and another +1 because the dictionary retains it. That’s a leak. Leave out yourretain
and it will be fine.dealloc
is correct. If there are no other strong references to the dictionary, it will get deallocated, releasing all objects contained in it. That means that your array will be deallocated, too, which is probably what you want.retainCount
.