Re: newbie EXC_BAD_ACCESS
Re: newbie EXC_BAD_ACCESS
- Subject: Re: newbie EXC_BAD_ACCESS
- From: Larry Fransson <email@hidden>
- Date: Sun, 20 Mar 2005 03:19:16 -0800
On Mar 20, 2005, at 2:11 AM, Daniel Child wrote:
// INITIATION AND DEALLOCATION
- (id)init
{
if (self = [super init])
{
knownStrokes = [NSMutableArray arrayWithCapacity: 100];
[self fillKnownStrokes]; // puts a bunch of stroke descriptons in the array
}
return self;
}
Why would something like this be autoreleased or otherwise "bad access"?
It's probably because you're using a class method (+arrayWithCapacity:) to initialize knownStrokes and it doesn't appear you're doing anything to retain knownStrokes. Class methods like +arrayWithCapacity:, etc. (generally any method that doesn't involve an alloc and init) return an autoreleased object. It's up to you to retain it if you want it to stick around. You need to make a change. Either this
knownStrokes = [[NSMutableArray arrayWithCapacity:100] retain];
or this
knownStrokes = [[NSMutableArray alloc] initWithCapacity: 100];
My method for debugging signal 10 and 11 crashes is to look for objects I haven't retained and retain them, or to eliminate release messages sent to other objects until the crash goes away. Then I figure out why there was a problem.
Larry Fransson
Seattle, WA
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden