アプリが読み込まれたときに、画像を配列に遅延読み込みしています。NSMutableArrayとNSArrayを使用してみました(作成後に配列を変更する必要はありません)が、後者がクラッシュします。
...
[self performSelectorInBackground:@selector(loadImageArrays) withObject:nil];
...
- (void)loadImageArrays {
NSAutoreleasePool *pool;
pool = [[NSAutoreleasePool alloc] init];
NSString *fileName;
imageArray = [[NSMutableArray alloc] init];
for(int i = 0; i <= x; i++) {
fileName = [NSString stringWithFormat:@"image_0000%d.png", i];
[imageArray addObject:[UIImage imageNamed:fileName]];
}
[pool drain];
}
vs
NSAutoreleasePool *pool;
pool = [[NSAutoreleasePool alloc] init];
imageArray = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"image_00000.png"],
[UIImage imageNamed:@"image_00001.png"],
[UIImage imageNamed:@"image_0000X.png"],
nil];
[pool drain];
NSZombieEnabled = YESは、後者のコードスニペットを使用したときに、[UIImageretain]が割り当て解除されたインスタンスに送信されたことを示します。両方の配列は、私のhファイルに(非アトミック、保持)プロパティを持っています。NSArrayによって画像が保持されないのはなぜですか?