メインバンドルから静的プロパティリストをロードします。十分に単純です。ただし、プロパティリストをnilに設定した後、プロパティリストの割り当てが解除されません。どうしてこれなの?プロパティリストが膨大なため、割り当てられたメモリは簡単に監視できます。
NSPropertyListFormat format = NSPropertyListBinaryFormat_v1_0;
NSError *error = nil;
NSArray *myArray = [NSPropertyListSerialization propertyListWithData:[NSData dataWithContentsOfFile:bundleFilePath]
options:NSPropertyListImmutable
format:&format
error:&error];
myArray = nil;
// Still takes up allocated space (as seen in memory monitor via instruments).
自動解放プールの場合:
- (void)someMethodCalledOnTheMainThread
{
@autoreleasePool {
NSString *bundleFilePath = @"...";
NSPropertyListFormat format = NSPropertyListBinaryFormat_v1_0;
NSError *error = nil;
NSArray *myArray = [NSPropertyListSerialization propertyListWithData:[NSData dataWithContentsOfFile:bundleFilePath]
options:NSPropertyListImmutable
format:&format
error:&error];
}
}