Do I have to auto-rank before the return form - (NSString *)?

Today I rewrote the description method (NSString *), and I wondered if this line should be auto-updated before it is returned.

-(NSString*)description { NSMutableString *response = [[NSMutableString alloc] init]; // perform appends return [response autorelease]; } 
+4
source share
2 answers

Yes, according to the ownership rule, your function should not delegate ownership of the returned string to the caller.

+7
source

Yes. Any method that does not start with alloc , new , copy or mutableCopy should not return a stored object. See Memory Management Rules

+2
source

All Articles