Hello. I am working on an iPhone app that will construct, at run-time, an NSMutableDictionary for which the values (of the key-value pairs) will be NSMutableArrays. Being somewhat new to the Objective-C, I am concerned that the following will cause a memory leak:
- (void) addNewSupplierPhoto:(UIImage*)image toSupplierID:(NSInteger*) supplierID{
NSMutableArray* supplierPhotoArray = [supplierPhotos objectForKey:supplierID];
if(supplierPhotoArray == nil)
{
supplierPhotoArray = [[NSMutableArray alloc] init];
[supplierPhotos setObject:supplierPhotoArray forKey:supplierID];
[supplierPhotoArray release];
}
}
supplierPhotos is an NSMutableDictionary, which is a member variable of the containing class.
As you can see, when I am accepting a new UIImage* to put into the structure, I first check to see if the object at the key-value pair corresponding to the second argument (supplierID) is nil. If it is nil, I alloc a new NSMutableArray and set it as the object for that key, then release it. Assuming I dealloc the NSMutableDictionary in the dealloc of the class containing this method, will the references be released? Before dealloc-ing the NSMutableDictionary, do I need to run through it and dealloc the individual NSMutableArrays contained within?
Thanks,
Ben B.