Should I autorelease before return form -(NSString*)description?
Today i was overwriting -(NSString*)description method and i wondered if need to autorelease this string before returning it.
-(NSString*)description {
NSMutableString *response = [[NSMutableString alloc] init];
// perform appe开发者_JAVA技巧nds
return [response autorelease];
}
Yes, as per ownership rule your function must not delegate the ownership of the returned string to the caller.
Yes. Any method whose name does not begin with alloc
, new
, copy
, or mutableCopy
should not return a retained object. See Memory Managment Rules
精彩评论