This may sound a newbie question, however I’m new to iOS dev.
I’ve declared NSURLConnection* mImageUploadConnection as instance member.
And running following to create it.
mImageUploadConnection = [[NSURLConnection alloc] initWithRequest:someRequest delegate:self startImmediately:YES];
The retain count is 2 after allocation, why ? (This maybe Apple inner stuff, right? I still need to release connection only once ?).
I’m releasing connection in
- didFailWithError
- connectionDidFinishLoading
methods, but I also need to cancel the connection is some case, when user pops from current navigation view. I.e. The cancellation can take place while the mImageUploadConnection hasn’t finished or failed. I cancel connection in following way
if (mUploadeImagConnection != nil) {
[mUploadeImageConnection cancel];
[mUploadeImagConnection release];
}
The connection gets cancelled correctly when is hasn’t finished or failed.
But the last code snippet fails (bad access) when connection has finished successfully, i.e. it has been released once.
- The retain count of mUploadeImagConnection is 1 when cancelling after
connection finished successfully, why it is so ??? - How can I check in last code snippet if connection status was
successful, and don’t send cancel message ?
Set your ivar to
nilafter you have released it.