NSURLConnection固有的内存泄漏? [英] NSURLConnection inherent memory leak?
问题描述
在 Xcode文档中的示例中URL加载系统编程指南:使用NSURLConnection ,它们分配
一个 NSURLConnection
( theConnection
),然后在回调中释放它: -connection:didFailWithError:
& -connectionDidFinishLoading:
.但是,如果在调用任一回调方法之前就释放了委托, theConnection
不会泄漏(即永远不会被释放)吗?
In the example in the Xcode Documentation : URL Loading System Programming Guide : Using NSURLConnection, they alloc
an NSURLConnection
(theConnection
) and then release it in the callbacks: -connection:didFailWithError:
& -connectionDidFinishLoading:
. But, won't theConnection
leak (i.e. never get released) if the delegate is released before either of the callback methods get called?
推荐答案
No, theConnection
won't leak because, as the Xcode Documentation for -[NSURLConnection initWithRequest:delegate:]
states under Special Considerations: "The connection retains delegate. It releases delegate when the connection finishes loading, fails, or is canceled."
这篇关于NSURLConnection固有的内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!