I have a case where I’m declaring an NSMutableArray and then testing it like so:
-(void)whatever {
NsMutableArray *array;
for(int i = 0; i < 10; i++) {
if(array){
[array release];
}
array = [[NsMutableArray alloc] init];
// Add things to the array and do stuff with those things before starting over
}
if ([array count] > 0) {
// Do something else
}
}
For some reason the if(array){} is evaluating to YES and it’s trying to release an object that doesn’t exist yet on the first pass through. It also evaluates to YES if I try if(array != nil){}. Is there a better way to test this?
When you declare your
arrayset it to nil:Otherwise you can get junk in the pointer.