• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Return causes EXC_BAD_ACCESS
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Return causes EXC_BAD_ACCESS (From: "Mr. Gecko" <email@hidden>)
 >Re: Return causes EXC_BAD_ACCESS (From: Dave DeLong <email@hidden>)
 >Re: Return causes EXC_BAD_ACCESS (From: "Mr. Gecko" <email@hidden>)
 >Re: Return causes EXC_BAD_ACCESS (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: Calculations in a tableview
  • Next by Date: Re: UI like Transmission BT
  • Previous by thread: Re: Return causes EXC_BAD_ACCESS
  • Next by thread: Re: Return causes EXC_BAD_ACCESS
  • Index(es):
    • Date
    • Thread