我目前正在从 JSON 解析我的所有数据并将其存储在一个数组中。然而,当它开始解析时,内存使用量从大约 25mb 跃升至 800mb。在做了一些研究之后,我被告知在 GCD 块中放置一个 @autoreleasepool 但无济于事。
这是我到目前为止的代码:
self.channelSchedules = [NSMutableArray new];
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Add code here to do background processing
//Loop through each channel object and download schedule
@autoreleasepool {
for (atlas_channel* channel in self.channels) {
NSLog(@"Updating listings for %@", [channel getChannelTitle]);
[self.channelSchedules addObject:[[channel getChannelSchedule] returnCurrentContentObject]];
[self.tableView reloadData];
[self scrollViewDidScroll:nil];
}
}
dispatch_async( dispatch_get_main_queue(), ^{
// Add code here to update the UI/send notifications based on the
// results of the background processing
[self.tableView reloadData];
});
});
我正在使用 TouchJSON 来解析数据。
经过进一步研究,我认为这与我将所有值一旦解析成一个 NSArray 就将其存储在内存中的事实有关。我想我将不得不使用 CoreData 或类似的东西。