Re: Return causes EXC_BAD_ACCESS
Re: Return causes EXC_BAD_ACCESS
- Subject: Re: Return causes EXC_BAD_ACCESS
- From: Jens Alfke <email@hidden>
- Date: Thu, 28 Jul 2011 16:14:26 -0700
On Jul 28, 2011, at 3:00 PM, Kyle Sluder wrote:
> I'm not sure what your motivation is for calling [self release] here,
> but no code should be doing this.
I disagree. There are a couple of reasons to call this:
- It’s pat of the failure path for -init methods. Before returning nil you need to call [self release] to avoid leaking.
- An object that performs some asynchronous task may want to retain itself when starting the task, and release itself when done, to make sure it won’t get dealloced before the task finishes.
Mr. Gecko wrote:
> I am still looking to an link to explanation in detail as to why this happens
If ‘foundCookieJar’ is an instance variable, than any time you refer to it in a method, the compiler actually implements it as “self->foundCookieJar”. From that, it should be pretty clear that if you set self to nil, the next reference to ‘self->foundCookieJar’ is a nil pointer access that’s going to crash.
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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