milof
milof

Reputation: 696

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?

Upvotes: 0

Views: 94

Answers (2)

ma11hew28
ma11hew28

Reputation: 126329

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.

Upvotes: 2

Manlio
Manlio

Reputation: 10865

Check the documentation, it'll be the fastest way

viewDidUnload
viewDidDisappear

Upvotes: 0

Related Questions