Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I autorelease before return form -(NSString*)description?

Tags:

objective-c

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 appends
    return [response autorelease];
}
like image 503
Guilherme Martinez Sampaio Avatar asked Jan 19 '23 20:01

Guilherme Martinez Sampaio


1 Answers

Yes, as per ownership rule your function must not delegate the ownership of the returned string to the caller.

like image 125
JustSid Avatar answered Feb 16 '23 04:02

JustSid