Crash with NSMutableArray and NSNumber
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.