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

resetting ivars safely


  • Subject: resetting ivars safely
  • From: Daniel Child <email@hidden>
  • Date: Wed, 12 Sep 2007 16:59:14 -0400

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....

Daniel

+ (WordParser *) sharedWordParser
{
	if (wordParser == nil) {
		wordParser = [[WordParser alloc] init];
	}
	return wordParser;
}

- (id) init
{
	if (self = [super init]) {
		[self setSyllables:      [[NSMutableArray alloc] init]];
		[self setWordCandidates: [[NSMutableArray alloc] init]];
	}
	return self;
}

// triggered when a GUI reset button is pressed
- (void) reset
{
[self setSyllables: nil]; // identically structured ivar has no problem for some reason
[self setWordCandidates: nil]; // PROBLEM OCCURS HERE
[self setCurrentCandidate: nil];
[self setHead: nil];
[self setTail: nil];
[self init];
}


// 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];
}
}



_______________________________________________

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: Uli Kusterer <email@hidden>
    • Re: resetting ivars safely
      • From: Chris Suter <email@hidden>
    • Re: resetting ivars safely
      • From: Chris Hanson <email@hidden>
    • Re: resetting ivars safely
      • From: Chris Hanson <email@hidden>
    • Re: resetting ivars safely
      • From: "Shawn Erickson" <email@hidden>
  • Prev by Date: Re: NSBrowser background color
  • Next by Date: Re: NSBrowser background color
  • Previous by thread: Re: warning: type `string' has a user-defined constructor
  • Next by thread: Re: resetting ivars safely
  • Index(es):
    • Date
    • Thread