4 時間が経過し、問題が見つかりました。で問題をどのように解決したかを説明しますXMLPerformance sample
。
問題はにありましたNSAutoreleasePool
。あります@property (nonatomic, assign) NSAutoreleasePool *downloadAndParsePool;
。アプリがダウンロードを開始すると、Top300 Paid Apps RSS
を使用して新しいスレッドが作成され[NSThread detachNewThreadSelector:@selector(downloadAndParse:) toTarget:self withObject:url];
ます。したがって、そのスレッドでは、ローカルの自動解放プールを保持する必要があります。それは次の方法で行われます。
- (void)downloadAndParse:(NSURL *)url {
self.downloadAndParsePool = [[NSAutoreleasePool alloc] init];
// initializing internet connection and libxml parser.
if (rssConnection != nil) {
do {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
} while (!done);
}
// Release resources used only in this thread.
[downloadAndParsePool release];
self.downloadAndParsePool = nil;
}
だから、downloadAndParse:
すべてがうまく見えます。次に、RSS からの項目が解析されるときに呼び出される 1 つのメソッドを見てみましょう。
- (void)finishedCurrentSong {
// sending new item to delegate and other ...
countOfParsedSongs++;
// Periodically purge the autorelease pool. The frequency of this action may need to be tuned according to the
// size of the objects being parsed. The goal is to keep the autorelease pool from growing too large, but
// taking this action too frequently would be wasteful and reduce performance.
if (countOfParsedSongs == kAutoreleasePoolPurgeFrequency) {
[downloadAndParsePool release];
self.downloadAndParsePool = [[NSAutoreleasePool alloc] init];
countOfParsedSongs = 0;
}
}
ご覧のとおり、次の行があります。
[downloadAndParsePool release];
self.downloadAndParsePool = [[NSAutoreleasePool alloc] init];
したがって、まさにその行が例外を引き起こします。それらにコメントすると、すべてうまくいきます。
しかし、その行をコメントするだけでなく、より効率的であると言われているブロックに置き換えることNSAutoreleasePool
に- (void)downloadAndParse:(NSURL *)url
しました。@autorelease
- (void)downloadAndParse:(NSURL *)url {
@autoreleasepool {
// initializing internet connection and libxml parser.
if (rssConnection != nil) {
do {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
} while (!done);
}
// Release resources used only in this thread.
}
}
今、すべてが正常に動作します。私が解決していない唯一の問題は次のとおりです。
// Periodically purge the autorelease pool. The frequency of this action may need to be tuned according to the
// size of the objects being parsed. The goal is to keep the autorelease pool from growing too large, but
// taking this action too frequently would be wasteful and reduce performance.
したがって、誰かがこの問題について考えている場合は、別の回答を投稿して、バグ修正をより正確に説明してみてください。その答えを喜んで受け入れます。
ありがとう。