I am initializing a view controller with a NSMutableArray. But in init, I have to init with NSMutableArray, but all the elements disappeared after that.
UIViewController* vc = [[[PhotoAlbumViewController alloc] initWithImages:imageArrayBig] autorelease];
Below is the definition of the function above.
// This is the definition of the init function
- (id)initWithImages:(NSMutableArray *)bigImages {
if ((self = [self initWithNibName:nil bundle:nil])) {
_imageArrayBig = [[NSMutableArray alloc] init];
for (ArrayObject* tmp in bigImages) {
[_imageArrayBig addObject: tmp];
}
}
// After the copying, all the elements in bigImages and _imageArrayBig disappear :(
return self;
}
Any idea? Is there a memory leak?
It looks like you are mixing the property name with the instance name since you use both
imageArrayBigand_imageArrayBig.It is better to stick with one, preferably
self.imageArrayBigwhich is the propertyYou can also copy the array more effectively by using
addObjectsFromArraysomething like