I have a calling method that looks like the following:
-(void)callingMethod { NSMutableString *myStr = [[[NSMutableString alloc] initWithCapacity:0] autorelease]; myStr = [self calledMethod]; }
And my called method:
-(NSMutableString*)calledMethod { NSMutableString *newStr = [[NSMutableString alloc] initWithCapacity:0]; // do some stuff with newStr return [newStr autorelease]; }
Am I leaking memory anywhere here? I feel like I’m allocing an unnecessary amount here.
No, you’re not leaking memory, but your instinct that you are allocing an unnecessary amount here is correct.
At a minimum, you should consider rewriting the
callingMethodas:You can also tidy up the
calledMethodas: