In terms of memory management, is it correct to modify the input variable content in the following method?
- (NSMutableArray *) extractResults:(NSString *)content {
...
regex = [NSRegularExpression ...];
content = [regex stringByReplacingMatchesInString:content
options:0
range:NSMakeRange(0, [content length])
withTemplate:@""];
...
}
In this particular case I do not care if the value remains modified outside the method scope. Just wondering if that assignment produces a memory leak.
Thanks!
No, it doesn’t produce a leak because the return value of
stringByReplacing...is autoreleased. However, you should be aware that you are not modifying thecontentobject at all.NSStringis immutable, so you can’t do that, you’re creating a new instance and assigning it to the variable.