• 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: newbie EXC_BAD_ACCESS
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: newbie EXC_BAD_ACCESS


  • Subject: Re: newbie EXC_BAD_ACCESS
  • From: Charilaos Skiadas <email@hidden>
  • Date: Sun, 20 Mar 2005 15:01:14 -0600

On Mar 20, 2005, at 2:50 PM, Daniel Child wrote:

Unfortunately, the suggestions below do not work. I still get the crash. I had also printed out retain counts on knownStrokes.

It might help if you show us the code for fillKnownStrokes, the new code you tried, and the backtrace of the crash. In fact, if you look at the backtrace, that should tell you exactly where the problem is.


One thing I don't understand. If I create an instance of StrokesArray "sa" having an instance variable knownStrokes, why should I have to specially retain knownStrokes. Shouldn't it come with sa itself.

Whoever creates "sa" doesn't have to retain knownStrokes. However, the instance "sa" of StrokesArray, when *it* is created, *it* creates knownStrokes, so *it* has to retain it, because it needs it. (I actually prefer not to think of it in terms of retain, but in terms of *own*. sa needs to own knownStrokes, so it needs to either alloc/init it, or retain the autoreleased object return by arrayWithCapacity.) Anyone who creates StrokesArray's from now on doesn't need to worry about knownStrokes, that's the StrokesArray instance's job.



Also, why do I have to specify the initial capacity of knownStrokes in the first place. Is there an advantage to the capacity methods below compared to plain old alloc/init?

You don't have to specify the initial capacity, though it helps the system slightly if you do. It should not really affect performance at this level (i.e. 100 elements). But if you ask the array eventually to handle 100000 elements, then it might help it if it knows about it in advance, so it can arrange how to store them.


On Sunday, March 20, 2005, at 02:53  AM, Jyrki Wahlstedt wrote:

On 20.3.2005, at 13:19, Larry Fransson wrote:


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.

Hi,
I can confirm this (probably => surely). I should know, I have done the same mistake in the beginning…

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden


_______________________________________________ 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
  • Follow-Ups:
    • Re: newbie EXC_BAD_ACCESS
      • From: Daniel Child <email@hidden>
References: 
 >Re: newbie EXC_BAD_ACCESS (From: Daniel Child <email@hidden>)

  • Prev by Date: Re: Access iTunes Playlists / tracks via Cocoa
  • Next by Date: Re: Creating a large Cocoa project - tutorials? - OT: underscore use
  • Previous by thread: Re: newbie EXC_BAD_ACCESS
  • Next by thread: Re: newbie EXC_BAD_ACCESS
  • Index(es):
    • Date
    • Thread