Re: Crash from NSURLConnection if delegate released too soon?
Re: Crash from NSURLConnection if delegate released too soon?
- Subject: Re: Crash from NSURLConnection if delegate released too soon?
- From: Jens Alfke <email@hidden>
- Date: Mon, 25 Aug 2014 09:54:07 -0700
> On Aug 25, 2014, at 9:40 AM, Howard Moon <email@hidden> wrote:
>
> Ok, I fixed it. I was using the connection object as a member of my class, and releasing that, when I should have been releasing the connection that is given to me inside didFailWithError and connectionDidFinishLoading, not making it a member at all.
It should be OK either way as long as you're following the ref-counting rules (or are using ARC.)
* Only release the NSURLConnection if you allocated it by calling +alloc
* Don't release the NSURLConnection instance passed into your delegate methods
Also, NSURLConnection instances always stay alive until the connection finishes (they are retained by CFNetwork internally) so you actually don't need to retain them yourself.
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden