I have a quick question about the two examples below. Currently I am using the top example on the understanding that because of the iPhones limited resources I am better off allocating and releasing manually as apposed to using the bottom string literal example. Does anyone have a preference as to which one to go with?
if(activeSegment == 0) {
NSString *newText = [[NSString alloc] initWithString:@"Hello World"];
[helloLabel setText:newText];
[newText release];
}
OR
if(activeSegment == 0) {
NSString *newText = @"Hello World";
[helloLabel setText:newText];
}
Personally I don’t think it matters in this case as I am setting the text on a label which wont be freed until the application exits anyway.
gary
The second option is definitely better. String literals are just pointers into your code, rather than allocated memory. The second version is a lot lower-weight. You could also just do: