URLからPNGファイルをダウンロードするNSURLConnectionがあります。コードは次のとおりです。
-(void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData {
if (data==nil) { data = [[NSMutableData alloc] initWithCapacity:2048]; }
[data appendData:incrementalData];
}
-(void)connectionDidFinishLoading:(NSURLConnection*)theConnection {
[self saveItLocal];
connection = nil;
data = nil;
}
-(void)saveItLocal {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *docs = [paths objectAtIndex:0];
NSString* path = [docs stringByAppendingFormat:[NSString stringWithFormat:@"/%@.png",self.downloadType]];
NSData* imageData = [NSData dataWithData:UIImagePNGRepresentation([UIImage imageWithData:data])];
NSError *writeError = nil;
[imageData writeToFile:path options:NSDataWritingAtomic error:&writeError];
if(writeError!=nil) {
NSLog(@"%@: Error saving image: %@", [self class], [writeError localizedDescription]);
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"readyWithGraphics" object:self];
imageData = nil;
}
なぜこのオブジェクトはまだ生きていて記憶に残っているのですか?