From a related thread, how should I have known the "mailString" below was already autoreleased?
//
+ (void) sendEmail:(NSString *) subject withBody:(NSString *)body {
NSString *mailString = [NSString stringWithFormat:@"mailto:?@&subject=%@&body=%@",
[subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[body stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailString]];
[mailString autorelease];
}
stringWithFormat:
is a convenience function that returns an autoreleased object.
I cannot recomment the Memory Management Guide highly enough. It really is worth reading, probably more than once.
since mailString is not created by the [[NSString alloc] init]; idiom it does need to be released.
You do not know that the object has been autoreleased.
All you know is that it is not your responsibility to release it.
You know that because it was returned to you from a method whose name did not begin with 'alloc', 'new', or contain 'copy', and you have never called 'retain' against it.
Reiterating what Eiko said - read Apples Memory Management Guide - it is very clear on this topic.
精彩评论