我想从MyViewController类做异步URL请求(具有UrlRequestor类):内存泄漏“dispatch_async(dispatch_get_main_queue(),{”块
UrlRequestor * urlRequestor = [UrlRequestor alloc] init]];
我设置MyViewController类为代表UrlRequestor类:
urlRequestor.delegate = self;
我打电话getUrlData功能:
[urlRequestor getUrlData];
它是UrlRequestor.m文件中的getUrlData函数,用于为多线程调度队列。它看起来如此:
- (void) getUrlData {
.......
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
......
dispatch_async(dispatch_get_main_queue(), ^{
........
[self.delegate receivedGetData: parsedResponseData withActionCode: [NSNumber numberWithInt: DASHBOARD_REQUEST_DONE]];
}
}
}
我跑的个人资料泄漏的工具,我收到内存在最后一排漏100%:
[self.delegate receivedGetData: parsedResponseData withActionCode: [NSNumber numberWithInt: DASHBOARD_REQUEST_DONE]];
我在的iOS是新的,我没有任何想法,为什么我在这里有内存泄漏。感谢帮助。
我现在试着“分析”。这是一个很好的工具,谢谢。但是这个问题的文件没有任何警告。 – Tatiana
我们可能应该将其移动到聊天:http://chat.stackoverflow.com/rooms/37800/memory-leak-when-delegate-is-called-from-dispatch-asyncdispatch-get-main-queue – Rob