• 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: resetting ivars safely
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: resetting ivars safely


  • Subject: Re: resetting ivars safely
  • From: "Shawn Erickson" <email@hidden>
  • Date: Wed, 12 Sep 2007 14:20:43 -0700

On 9/12/07, Daniel Child <email@hidden> wrote:
> HI All,
>
> I am trying to find a way to safely reset or reinitialize the
> instance variables of a singleton object. A "word parser" behaves
> correctly the first couple of times it is used, but then self-
> destructs. Everything goes fine the first time through, but on the
> second or third attempt to reset the wordCandidates ivar, an EXC-BAD-
> ACCESS signal is generated just prior to releasing the ivar in its
> setter (using the release, then copy paradigm). Since the retain
> count prior to releasing is 1, I am mystified.
>
> Here is the relevant code. Thanks much....
>
> // setter for wordCandidates ivar
> - (void) setWordCandidates: (NSMutableArray *) wc
> {
>         if (wc != wordCandidates) {
>                 printf("wordCandidates retain count prior to release is %i.\n",
> [wordCandidates retainCount]); // equal to 1
>                 [wordCandidates release]; // EXC-BAD-ACCESS COMES HERE
>                 wordCandidates = [wc mutableCopy];
>         }
> }

What do you see in the run log if you replace the printf above with
the following line (is it a mutable array with objects that you
expect, etc.)...

NSLog(@"wordCandidates=%@", wordCandidates);

Also are you sure the bad access is at the exact message send or does
it happen while the target object is handling that message (in other
words while the NSMutableArray is releasing the objects it contains,
assuming your release triggers deallocation of the array).

-Shawn
_______________________________________________

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

  • Follow-Ups:
    • Re: resetting ivars safely
      • From: Daniel Child <email@hidden>
References: 
 >resetting ivars safely (From: Daniel Child <email@hidden>)

  • Prev by Date: Custom pagination clipping
  • Next by Date: Re: warning: type `string' has a user-defined constructor
  • Previous by thread: resetting ivars safely
  • Next by thread: Re: resetting ivars safely
  • Index(es):
    • Date
    • Thread