Using alloc vs not when creating the string in description


#1

In the “For the more curious” section of Chapter 20, the description method uses alloc to create the string that it plans to return:

NSString *result = [[NSString alloc] initWithFormat:@"<%@: $%d >", [self label], [self resaleValue]]; [result autorelease]; return result;

In our Employee example earlier in the chapter, we use the following:

For the non-ARC version in Asset.m (example 1 above), why can’t we use the class version of the “stringWithFormat” method like we do in the ARC version (example 2 above) (instead of using alloc, which implies that we are using the instance version of “stringWithFormat”)? It seems to me that this would avoid the need to worry about an owner in the first place and just create the string to be returned from the function like in example 2 above. Was this just done for the purposes of an example, or am I missing something?