If I try and release tempSeedsArray after seedsArray = tempSeedsArray , I get an EXEC_BAD_ACCESS, and Instruments shows that tempSeedsArray has been released twice. Here is my viewWillAppear method:
- (void)viewWillAppear:(BOOL)animated {
NSString *arrayFilePath = [[NSBundle mainBundle] pathForResource:@"SeedsArray" ofType:@"plist"];
NSLog(@"HIT!");
NSMutableArray *tempSeedsArray = [[NSMutableArray alloc] initWithContentsOfFile:arrayFilePath];
seedsArray = tempSeedsArray;
NSLog(@"%u", [seedsArray retainCount]);
[seedsArray sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
[super viewWillAppear:animated];
}
seedsArray is an NSMutableArray set as a nonatomic and a retain property, and is synthesised.
However, if I change seedsArray = tempSeedsArray to self.seedsArray = tempSeedsArray (or [self seedsArray] = tempSeedsArray etc.), I can release tempSeedsArray. Could someone please explain simply to me why this is, as I am very confused!
Thanks