What is the difference between these two different lines of Objective-C, and why does one work and n

Posted by jrtc27 on Stack Overflow See other posts from Stack Overflow or by jrtc27
Published on 2010-04-12T10:13:29Z Indexed on 2010/04/12 12:53 UTC
Read the original article Hit count: 303

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

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone-sdk