• 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
Crash with NSMutableArray and NSNumber
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Crash with NSMutableArray and NSNumber


  • Subject: Crash with NSMutableArray and NSNumber
  • From: <email@hidden>
  • Date: Fri, 10 Jan 2003 3:17:15 +1100

I have a problem with a current program. The layout is as follows.
The main data source is held in a NSMutableArray. The source is a group of custom NSObjects (MyData) which are used to display information on the screen.
The NSMutableArray is declared with;

_myArray = [[NSMutableArray alloc] init] ;

When I wish to refresh the screen a call an instance called Render using the following;

Render * render = [[Render alloc] init] ;
[render displayScreen: self] ;
[render release] ;

Render then looks something like this;

- (void)displayScreen: (id)sender
{
int numberOfLines, x ;
int originalNumber ;
MyData * myData = [[MyData alloc] init] ;
NSNumber * number = [[NSNumber alloc] init] ;
.
numberOfLines = [sender getNumberOfLines] ;
.
for( x = 0; x < numberOfLines; x++ )
{
myData = [sender getLine: x] ;
number = [myData getNumber ] ;
originalNumber = [number intValue] ;
.
}
[number release] ;
[myData release] ;
}

to return the value for myData and numberOfLines the following are used;

- (int)getNumberOfLines
{
return [_myArray count] ;
}
- (MyData *)getLine: (int)index
{
return [_myArray objectAtIndex: index] ;
}

similarly within MyData I have the following

@interface MyData : NSObject
{
NSNumber * aNumber ;
NSString * aString ;
NSNumber * anotherNumber ;
.
}

to recover aNumber
- (NSNumber *)getNumber
{
return aNumber ;
}

My problem is as follows, the first time I run the redraw routine everything works as expected, but the second time I run it, any calls to returned NSNumber items return a EXC_BAD_ACCESS error in the debugger, so the line originalNumber = [number intValue] causes a crash. However similar calls to returned NSString items are not affected.

Stepping through the code at runtime reveals that the all of the values for the NSString items remain constant, however the isa reference number changes from one execution to the next on the NSNumber items.

Is this the cause of my crash? Or what suggestions can you offer?

Thanks,

Andrew...

This message was sent through MyMail http://www.mymail.com.au
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: NSConnections: Can they retrieve objects?
  • Next by Date: Java Cocoa
  • Previous by thread: Re: Non-activating panel not working
  • Next by thread: Re: Crash with NSMutableArray and NSNumber
  • Index(es):
    • Date
    • Thread