1

NSXMLDocument を介してバックグラウンドで複数の同時 XML ドキュメントの解析が行われていますが、ドキュメントには NSXMLDocument がスレッドセーフであると記載されていても、安全ではないと思います。このエラーがランダムに発生しています:

Warning: NSBundle NSBundle </System/Library/PrivateFrameworks/XQuery.framework> (loaded) was released too many times. For compatibility, it will not be deallocated, but this may change in the future. Set a breakpoint on __NSBundleOverreleased() to debug

また、解析中にドキュメントが失敗します。GCD キューをシリアルに切り替えると、問題は解決します。私が間違っていることはありますか?

これを実行しているコードのサンプルを次に示します (XML 解析は ForecastDownloader で行われます)。

NSMutableArray *weatherObjects = [[NSMutableArray alloc] init];

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_group_t group = dispatch_group_create();

dispatch_queue_t serialQueue;
serialQueue = dispatch_queue_create("us.mattshepherd.ForecasterSerialQueue", NULL);

for (NSDictionary *theLocation in self.weatherLocations) {

    // Add a task to the group
    dispatch_group_async(group, queue, ^{
        NSLog(@"dispatching...");
        ForecastDownloader *forecastDownloader = [[ForecastDownloader alloc] init];
        int i = 0;
        WeatherObject *weatherObject = [forecastDownloader getForecast:[theLocation objectForKey:@"lat"] lng:[theLocation objectForKey:@"lng"] weatherID:[[theLocation objectForKey:@"id"] intValue]];

        }
        if(!weatherObject){
            //need to implement delegate method to show problem updating weather
            NSLog(@"problem updating weather data");
        }else{
            NSLog(@"got weather for location...");
            dispatch_sync(serialQueue, ^{
                [weatherObjects addObject:weatherObject];
            });


        }
    });

}
// wait on the group to block the current thread.
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);

NSLog(@"finished getting weather for all locations...");
//we will now do something with the weatherObjects
4

0 に答える 0