Objective-C ARCアプリケーションで、配列を割り当てるのにどこが良いかを理解しようとしています。
ケース1:解析関数の外部で配列を割り当てて初期化する
- (void)viewDidLoad { // or another method
// other code
// here I alloc and init arrays:
dataSource2 = [[NSMutableArray alloc] init];
dataSource3 = [[NSMutableArray alloc] init];
dataSource4 = [[NSMutableArray alloc] init];
dataSource5 = [[NSMutableArray alloc] init];
dataSource6 = [[NSMutableArray alloc] init];
dataSource7 = [[NSMutableArray alloc] init];
dataSource8 = [[NSMutableArray alloc] init];
dataSource9 = [[NSMutableArray alloc] init];
}
- (void)parseFunction {
// parsing code
// do something with arrays and iterate, example:
for (int i = 1; i < [arrays count]; ++i) {
[dataSource2 addObject:object2];
[dataSource3 addObject:object3];
[dataSource4 addObject:object4];
[dataSource5 addObject:object5];
[dataSource6 addObject:object6];
[dataSource7 addObject:object7];
[dataSource8 addObject:object8];
[dataSource9 addObject:object9];
}
}
ケース2:解析関数内および反復サイクル外のallocおよびinit配列
- (void)viewDidLoad { // or another method
// other code
}
- (void)parseFunction {
// here I alloc and init arrays:
dataSource2 = [[NSMutableArray alloc] init];
dataSource3 = [[NSMutableArray alloc] init];
dataSource4 = [[NSMutableArray alloc] init];
dataSource5 = [[NSMutableArray alloc] init];
dataSource6 = [[NSMutableArray alloc] init];
dataSource7 = [[NSMutableArray alloc] init];
dataSource8 = [[NSMutableArray alloc] init];
dataSource9 = [[NSMutableArray alloc] init];
// parsing code
// do something with arrays and iterate, example:
for (int i = 1; i < [arrays count]; ++i) {
[dataSource2 addObject:object2];
[dataSource3 addObject:object3];
[dataSource4 addObject:object4];
[dataSource5 addObject:object5];
[dataSource6 addObject:object6];
[dataSource7 addObject:object7];
[dataSource8 addObject:object8];
[dataSource9 addObject:object9];
}
}
ケース3:解析関数内および反復サイクル内のallocおよびinit配列
- (void)viewDidLoad { // or another method
// other code
}
- (void)parseFunction {
// parsing code, alloc init and iterate, all in the same cycle:
for (int i = 1; i < [arrays count]; ++i) {
dataSource2 = [[NSMutableArray alloc] init];
dataSource3 = [[NSMutableArray alloc] init];
dataSource4 = [[NSMutableArray alloc] init];
dataSource5 = [[NSMutableArray alloc] init];
dataSource6 = [[NSMutableArray alloc] init];
dataSource7 = [[NSMutableArray alloc] init];
dataSource8 = [[NSMutableArray alloc] init];
dataSource9 = [[NSMutableArray alloc] init];
[dataSource2 addObject:object2];
[dataSource3 addObject:object3];
[dataSource4 addObject:object4];
[dataSource5 addObject:object5];
[dataSource6 addObject:object6];
[dataSource7 addObject:object7];
[dataSource8 addObject:object8];
[dataSource9 addObject:object9];
}
}
さて、私のアプリケーションは3つのケースすべてでクラッシュすることなく動作しますが、多数の配列をどこに割り当てる必要があるかについての説明を読みたいと思います。それは同じことですか?または、パフォーマンスとメモリ割り当ての観点から、いくつかの問題を回避するための最良の位置がありますか?ありがとう!