What is the proper place to release a NSURLConnection in the following example?
I have the following statement in my viewWillAppear controller:
开发者_开发问答connectionInprogress = [[NSURLConnection alloc]initWithRequest:request delegate:self startImmediately:YES];
What is the proper place to release it? That is can I just do it in viewDidUnload or does it make more sense to do it in viewDidDissapear?
I guess the fundamental question here is that does viewDidUnload get called every time a viewDidDissapear gets called?
No viewDidUnload
is paired with viewDidLoad
and may never get called, which is why you should also release your instance variables in dealloc
. viewDidUnload
is called if the view controller is sent a memory warning.
You should release theNSURLConnection
in the callback functions: connectionDidFinishLoading:
and connection:didFailWithError:
. Only one will be called.
Check out the Xcode documentation for URL Loading System Programming Guide : Using NSURLConnection.
Check the documentation, it'll be the fastest way
viewDidUnload
viewDidDisappear
精彩评论