我搜索了很多內容,並閱讀了很多關於NSURLConnection的泄漏問題,但是他們都沒有給出關於克服這些泄漏的解決方案的明確答案。 我創建了一個異步連接,每次建立連接時,我都會得到一個GeneralBlock-3584泄漏。有時候負責的庫被顯示爲基礎[NSThread start]框架。 GeneralBlock-3584的某些實例將CFNetwork HostLookup_Master :: HostLookup_Master(__ CFString const *,InheritEnum < _ExtendedHostInfoType,CFHostInfoType>,__CFHost *,CFStreamError *)作爲負責任的框架。 我試圖設置NSURLCache大小爲0建議的一些。 Howvever,即使這樣也行不通。NSURLConnection中的泄漏
這裏是我的連接器類的樣子:
-(void) connectToUrl:(NSString*)urlStr withDelegate:(id)theDelegate{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"GET"];
[request setValue:@"application/xml" forHTTPHeaderField:@"Content-Type"];
self.delegate = theDelegate;
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
[NSURLConnection connectionWithRequest:request delegate:self];
[pool release];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
if(xmlResponse == nil){
xmlResponse = [[NSMutableString alloc] initWithData:data encoding:NSISOLatin1StringEncoding];
}
else{
NSMutableString *temp = [[NSMutableString alloc] initWithData:data encoding:NSISOLatin1StringEncoding];
[xmlResponse appendString:temp];
[temp release];
}
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
[self.delegate connectionDidFinish:self];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
[self.delegate connectionDidFail:self];
}
我打電話來此連接器類的connectToUrl:(的NSString *)urlStr withDelegate:(ID)theDelegate方法如下:
Connector *con = [[Connector alloc] init];
[con connectToUrl:urlStr withDelegate:self];
我正在釋放委託類的connectionDidFinish和connectionDidFail方法中的'con'。
請爲GeneralBlock-3584泄漏提出解決方案。我一直在絞盡腦汁。