When I remove array, do I have remove each element of dictionary also?
NSMutableArray *myArry = [NSMutableArray arrayWithCapacity:100];
NSMutableDictionary *myDic = [NSMutableDictionary dictionaryWithCapacity:10];
[myArray addObject:myDic]; // this is done in loop
[myDic removeAllObjects]; // Is this necessary?
[myArray removeAllObjects];
No. When you
releasean array, every item inside is automatically send areleasemessage so you are not required to remove them, release them or adjust them other that simply releasing the array using-[NSArray release]The correct code is
A
NSDictionarybehaves in the same way, that is, you do not need to remove them, only release them. In the move example, the dictionaries you are adding are autoreleased meaning that oncemyArrayreleases them, they will be dealloc’d