Having a problem with NSURLConnection, if I create a NSURLConnection and call [connection connectionWithRequest] let it load a little then call [connection cancel] most of the time that works fine. However occasionally even after I call [connection cancel] the connection’s delegate still gets called (which crashes the app). Googling around it looks like the problem here is a race condition in the runloop, I cancel the connection and release the delegate but before the runloop cycles it calls the delegate functions -> crash.
Is there a way for me to, after I call [connection cancel] confirm the connection has actually canceled? Even a crappy while() loop will do 🙁
You should not release the connection & associated storage until your delegate receives either a
connectionDidFinishLoading:or aconnectionDidFailWithError:message.Delegates are not normally retained by the object they’re acting as delegate for. However in this case it is, so the delegate should not become invalid while the NSURLConnection is still referring to it, unless you’re over-releasing it somehow.