NSURLConnection sendSynchronousRequest - is it possible to implement without leak

二次信任 提交于 2019-12-11 09:19:00

问题


Is there a way to implement NSURLConnection without it leaking? A number of Apps including NYTimes and others (including mine) suffer from this. Anyone have a working implementation?


回答1:


It appears that best practice is to use NSURLConnection asynchronously.




回答2:


According to the documentation, +[NSURLConnection sendSynchronousRequest:returningResponse:error:] is built on top of the asynchronous loading code made available by NSURLConnection. It would not be difficult to reimplement this by spawning and blocking on an NSThread, running the request asynchronously in the background on a run loop and ending the thread once either connectionDidFinishLoading: or connection:didFailWithError: is received.

Of course, you are better off using the asynchronous code in the first place; it makes for a much better user experience



来源:https://stackoverflow.com/questions/1330135/nsurlconnection-sendsynchronousrequest-is-it-possible-to-implement-without-lea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!