One thing I’m concerned about is I create two ints, but don’t release them. Would it be better to make them NSIntegers?
-(void) flipCoin {
int heads = [headsLabel.text intValue];
int tails = [tailsLabel.text intValue];
if (random() %2 ==1 )
{
heads++;
}
else {
tails++;
}
headsLabel.text = [NSString stringWithFormat:@"%d", heads] ;
tailsLabel.text = [NSString stringWithFormat:@"%d", tails];
}
intis what is known as a primitive type. It is not a pointer to an Objective-C object so you cannot release it. You can’t even send a message to it.NSInteger is also a primitive type in the sense that it is a typedef to a primitive type (long usually). So you can’t release that either.
What do you need to release? You need to release any object you obtained by sending new, alloc or a method containing copy. You also need to release objects to which you have sent retain. So all of the local variables in the following must be released:
NB due to implementation details, you would actually get away with not releasing the aString4 but you don’t need to worry about it.