NSMutableArray *tempData=[[NSMutableArray alloc]init];
TBXMLElement * city = [TBXML childElementNamed:@"city" parentElement:root];
while(city!=nil){
if([TBXML valueOfAttributeNamed:@"name" forElement:city]!=nil){
NSString *tempDataHolder=[NSString stringWithFormat :@"%@,%@",[TBXML valueOfAttributeNamed:@"name" forElement:city],[TBXML valueOfAttributeNamed:@"country_name" forElement:city]];
[tempData addObject:[tempDataHolder copy]];
[tempDataHolder release];
}
city = [TBXML nextSiblingNamed:@"city" searchFromElement:city];
}
tableData=[tempData copy];
[tableCities reloadData];
[tempData release];
Instruments with Memory leaks says there is a leak of multiple NSCFStrings,i have been trying to figure it out for a while, any help is highly appreciated.
Thanks
edit: The above set of code runs a few times, and i have a bunch of leaks referring to NSCFString – NSPlaceholderString. I am releasing tempDataHolder almost immediately and the rest of the variables are being released as well. I cant pin point on where the leak is.
Copied objects need to be released by the owner. That is, the
copymethod returns a new object that has a retain count of 1. In your situation, the culprit seems to be this line:Containers retain their elements, but the copied object already has a retain count of 1 before being inserted in the array. The copied object is therefore leaking.
Simply adding
tempDataHolderin your array (not a copy) should solve it.Also,
tempDataHolderis an auto-released object and shouldn’t be released explicitly.