これは本当に奇妙なバグです。NSURlConnectionキャンセル原因メモリリーク
私はダウンロードが完了したら、NSURLConnection
とファイルをダウンロードするためのコードを使用しています、私は漏れがありません。 しかし、私がダウンロードをキャンセルすると、1Mメモリーが解放されていません。 私は楽器を使用してテストを行う必要があり、このリークを作成するために特定されMethodeのは
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
であるが、これは、ダウンロード
ノートを作成、管理、および取り消しのための私のコードです
本当に不思議です。このダウンロードコアデータ管理オブジェクトの一部ですが、コアデータが自分のリークの原因ではないと私は考えています。
- (void)loadURL:(NSURL *)url
{
if (currentLoadingDatas) { // just bool for prevent multiple download
return;
}
currentLoadingDatas = YES;
NSURLRequest *request = [[NSURLRequest alloc]
initWithURL: url
cachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval: 60
];
connectionDatas = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[request release];
}
#pragma mark NSURLConnection Delegates
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
if (!self.transientData) {
self.transientData = [[NSMutableData alloc] init];
}
[self.transientData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[self.transientData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[self willChangeValueForKey:@"datas"];
[self setValue:self.transientData forKey:@"datas"];
[self didChangeValueForKey:@"datas"];
[self.transientData release];
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
[sharedCache release];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
[sharedCache release];
}
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse
{
return nil;
}
-(void)cancelDownload
{
[self.connectionDatas cancel];
}
// fired by coreData
-(void)willTurnIntoFault
{
self.transientData = nil;
[self cancelDownload];
[super willTurnIntoFault];
}
// fired by coreData
-(void)didTurnIntoFault
{
[connectionDatas release];
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
[sharedCache release];
[self.transientData release];
[super didTurnIntoFault];
}
問題の特定にご協力いただけますか?
ありがとうございます。
あなたの助けてくれてありがとう、今私はより安全なコードのためにイーグルスを使用できる方法を理解しています。 – Pixman