Is the following legal in Objective-c with ARC enabled?
NSMutableArray * smallArray = [[NSMutableArray alloc] initWithObjects:@"1", @"2", @"3", nil];
smallArray = [[NSMutableArray alloc] initWithObjects:@"4", "5", nil];
I thought it should be. However, in this situation it gives me EXEC_BAD_ACCESS on the forth line:
NSMutableArray * bigArray = [[NSMutableArray alloc] init];
NSMutableArray * smallArray = [[NSMutableArray alloc] initWithObjects:@"1", @"2", @"3", nil];
[bigArray addObject: smallArray];
smallArray = [[NSMutableArray alloc] initWithObjects:@"4", "5", nil];
addObject copies the pointer right? So if I allocate a new segment of memory to smallArray to point to, what is wrong with that?
However this code segment does not crash:
NSMutableArray * bigArray = [[NSMutableArray alloc] init];
NSMutableArray * smallArray = [[NSMutableArray alloc] initWithObjects:@"1", @"2", @"3", nil];
[bigArray addObject: smallArray];
smallArray = [[NSMutableArray alloc] init];
[smallArray addObject:@"4"];
[smallArray addObject:@"5"];
What's going on here?
initWithObjects:@"4", "5", nil]... have you lost@before"5"??