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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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."