Iphone – When to release NSUrlConnection object

iphone

What is the correct point at which to release a NSUrlConnection object?

In my program, I alloc a NSUrlConnection, and then initWithRequest to kick off asynchronously.

I am now responsible for releasing the object – when do I/can I release? Immediately if I'm not using it again?

Best Answer

When you are done with the NSURLConnection. You'll know you're done with it when your NSURLConnection delegate receives - (void)connectionDidFinishLoading:(NSURLConnection *)connection or - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error. Just release it at the end of those two methods.