Newbie SIGBUS Error

Newbie SIGBUS Error

Post by publiclo » Tue, 22 Jul 2003 00:35:50




> Well there is some confusing input on how it actually works:

>    a) retain/release have been implemented as "NOPs" for constant strings

There was never anything wrong with the use of constant strains and
the constant string was never involved in the crash.  a) is true and
irrelevant to the crash.

Quote:>    b) retain/release work, but dealloc causes the thing to crash

b) is also true. The code uses an NSArray instance that was released
one too many times resulting in the crash.

Here is the code that was posted:

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];



  int count = [array count];

  int i;
  for (i = 0; i < count; i++) {
    printf("%i: %s\n", i, [[array objectAtIndex:i] UTF8String]);
  }

  [string release];
  // This release causes a "arrays has exited due to signal 10
(SIGBUS)."
  // [array release];
  [pool release];
  return 0;

Quote:}

As even David Stes can see, no alloc or copy message was involved in
obtaining the array instance and the array instance was not retained.
Therefore it should not be released.  In fact, when the line that
conatines [array release] was commeneted out as shown above, the crash
was eliminated.

The rules explained many times in this forum are as follows:
If an instance was obtained with a message that includes the words
"alloc" or "copy" or the instance was retained, it SHOULD be released
or autoreleased.  If the instance was NOT obtained with a message that
includes the words "alloc" or "copy" and the instance was NOT retained
then the instance SHOULD NOT be released or autoreleased.

 
 
 

Newbie SIGBUS Error

Post by John C. Randolp » Wed, 23 Jul 2003 12:53:41



> John Randolph (who is a faithful Apple maniac, working at Apple in fact)

You know, David, when someone like you calls me a maniac, I know I'm
doing something right.

-jcr