Reputation: 1
I've searched and have no answer. I've created an NSMutableArray and am getting an EXC_BAD_ACCESS error in one place of access. Here. This is declaring in the .h file:
NSMutableArray *buttons;
...
@property (nonatomic, retain)NSMutableArray *buttons;
And this is the synthesizing and implimenting:
@synthesize buttons;
...
- (id)init {
self = [super init];
if(self != nil) {
buttons = [[NSMutableArray alloc] init];
}
return self;
}
...
-(void)addButtonWithImage:(Image*)image {
Image *button = image;
[buttons addObject:button];
[button release];
}
...
-(void)replaceButtonAt:(int)num with:(Image*)image {
Image *button = image;
[buttons replaceObjectAtIndex:num withObject:button]; <<===EXC_BAD_ACCESS
[button release];
}
But when I use this:
-(void)renderButton:(int)num atPoint:(CGPoint)point center:(BOOL)center{
Image *button = [buttons objectAtIndex:num];
[button renderAtPoint:point centerOfImage:center];
}
It works
Upvotes: 0
Views: 164
Reputation: 70785
since you never allocate, retain, copy, etc. button
you should not be releasing it
just get rid of the [button release]
s
The Memory Management Programming Guide for Cocoa is a useful read if you need more info on reference counting.
Upvotes: 4