How to release a string created inside a method in iphone?

Posted by Warrior on Stack Overflow See other posts from Stack Overflow or by Warrior
Published on 2011-01-05T07:48:05Z Indexed on 2011/01/05 7:53 UTC
Read the original article Hit count: 192

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

© Stack Overflow or respective owner

Related posts about iphone

Related posts about memory-management