How to release a string created inside a method in iphone?
- by Warrior
I have declared a local string inside the method.I am releasing the string inside the same method.I found my code crashing if release that object.If i dont release the string,code runs successfully.I have called that method in viewdidappear so that method is called while pushing and poping.Nothing gets printed in the console. Here is my code
-(void)appendString{
NSString *locStr = [[NSString alloc] initWithString:@""];
for (int i=0;i<[result count]; i++)
{
locStr=[locStr stringByAppendingFormat:@"%@",[result objectAtIndex:i]];
}
[str setString:locStr];
[locStr release];
}
I am calling the "appendString" method from "viewDidAppear"."str" is a NSMutable string declared in .h class.How should i release the "locStr" .Please help me out