NSMutableArray addObject crashes in the device but works in the simulator in order

I have a set of images in my project, for example,

enter image description here

I am trying to connect them to a mutable array. In this way,

NSMutableArray *imageArray = [[[NSMutableArray alloc] initWithCapacity:36] retain];
for (int i = 0; i < 36; i++) {
    UIImage *image = [[UIImage imageNamed:[NSString stringWithFormat:@"quicktour_%d.JPG",i+1]] autorelease];
    [imageArray addObject:image];
}

This works in the simulator just fine, but it crashes when launched in the device after adding as many as 5 images.

This is a project without ARC. I reviewed all of these similar issues here on SO, and tried the solutions posted there, but my problem still exists.

Can anyone help me out?

Thanks in advance.

EDIT:

This is the result that appears on the console on failure.

***** - "NSInvalidArgumentException", : " * - [__ NSArrayM insertObject: atIndex:]: nil ' * : (0x2f784f4b 0x39bc56af 0x2f6bec81 0x138987 0x31f2c713 0x31f2c6b3 0x31f2c691 0x31f1811f 0x31f2c107 0x31f2bdd9 0x31f26e65 0x31efc79d 0x31efafa3 0x2f750183 0x2f74f653 0x2f74de47 0x2f6b8c27 0x2f6b8a0b 0x343df283 0x31f5c049 0x1f9ab 0x3a0cdab7) lib++ abi.dylib: NSException **

+3
2

, addObject:, . , , , , imageNamed: nil. iOS , OS X () ; , , .

, , nil .

+3
  • , ?
  • NSLog , , , , , .
  • , NSLog, , , , , , .
  • , . ARC. ? , , autorelease, "autorelease" , , .

:

NSMutableArray *imageArray = [[[NSMutableArray alloc] initWithCapacity:36] retain];
for (int i = 0; i < 36; i++) {
    UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"quicktour_%d.JPG",i+1]];
    [imageArray addObject:image];
    [image release];
    image = nil;
}
+1

All Articles