Hi,
I have the following method:
-(void)testAPIModule {
self.requests = [NSMutableArray array];
NSLog(@"making arrays");
/*(A)*/ id array1 = [NSArray arrayWithObjects:[NSNumber numberWithInt:1], [NSNumber numberWithFloat:2], nil];
/*(B)*/ id array2 = [NSArray arrayWithObjects:[NSNumber numberWithInt:4], [NSNumber numberWithInt:5]];
NSLog(@"made array=%@",array2);
for( ServerRequest *req in self.requests ) {
[Networker sendRequest:req withDelegate:self];
[req release];
}
}
The code runs as expected.
However, if I comment out line (A) OR remove the ",nil" at the end of it, I get an EXC_BAD_ACCESS
error at line (B)! According to the debugger, the error occurs in CFRetain in the +[NSArray arrayWithObjects] built-in constructor.
In addition, if I comment out line (A) and comment out the for(...) loop, the code runs through the method.
This is very unexpected to me. What am I doing wrong on line (B)? And why would creating a completely different array on line (A) let the method run through? And why does commenting out the for(...) loop prevent the error on line (B) that is before it?
Can someone explain why this is? Or at least give me some advice for debugging? I've already verified that the method is only running once and that "self" is valid.