• 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: sigbus error 10 (newbie)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sigbus error 10 (newbie)


  • Subject: Re: sigbus error 10 (newbie)
  • From: Hamish Allan <email@hidden>
  • Date: Sat, 19 Mar 2005 02:55:59 +0000

Daniel,

You need to learn about Objective-C memory management right from first principles. You're doing all sorts of things wrong:

-- allocating objects and then leaking them straight away (if you know C, what you're doing is equivalent to e.g. "int *p = malloc(xsize); p = other_p" which doesn't free the allocated memory, merely loses the pointer to it. If you don't know C, learn that first).
-- trying to release the objects in an array every time round the loop. (This would be equivalent to having a C array of pointers and calling free() on them multiple times round a loop).
-- You should be returing an autoreleased object.


I suggest you read a good book or web tutorial (e.g., http://www.macdevcenter.com/pub/a/mac/2001/07/27/cocoa.html). But make sure you have a good understanding of pointers in straight C first.

Best wishes,
Hamish

Hi All,

Just when I thought I was getting the hang of this.... I keep getting a
signal 10 or signal 11 error with the following code:

// This method takes a string representing a stroke description (e.g.
"SS-EE-SE")
// and checks the knownStrokes array to find out what types of strokes
this
// description may correspond to. Usually, a description may correspond
to only
// one kind of stroke, but occasionally the returned set of matching
types may
// have more than one members in the set.
- (NSMutableSet *)strokeTypesHavingDescription:(NSString *)d
{
   int i = 0;
   NSMutableSet *matchingTypes = [[NSMutableSet alloc] init];
   NSString *thisDesc = [[NSString alloc] init];
   NSNumber *thisType = [[NSString alloc] init];

   for (i = 0; i < numInList; i++)
   // Note: numInList is a member variable that counts knownStrokes
   {
     thisDesc = [[knownStrokes objectAtIndex: i] desc];
     thisType = [[knownStrokes objectAtIndex: i] strokeType];
     // printf("thisType %i   thisDesc %s\n", [thisType intValue],
[thisDesc cString]);
     if ([thisDesc isEqualToString: d])
     {
       [matchingTypes addObject: thisType];
       printf("types retaincount is %i\n\n", [matchingTypes
retainCount]);
     }
     // [thisDesc release];
     // [thisType release];
   }
   printf("matchingTypes set's retain count is %i\n", [matchingTypes
retainCount]);
   return matchingTypes;
}

I've been fiddling with this for ages and can't see what is wrong. I
have tried it with and without the release lines, as well as with or
without the alloc/init following the variable declarations.

By the way, are the signal/sigbus error numbers useful hints at what is
wrong?

Thanks in advance.

Daniel

_______________________________________________ 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
  • Prev by Date: Re: slow NSWorkspaceDidWakeNotification
  • Next by Date: Progress bar
  • Previous by thread: sigbus error 10 (newbie)
  • Next by thread: Re: sigbus error 10 (newbie)
  • Index(es):
    • Date
    • Thread