My code leaks but I do not know exactly what am I doing wrong. Simply I have a function that takes array with NSStrings and outputs NSString formatted as CSV.
Here is my code:
-(NSString*)generateCSVfromArray: (NSMutableArray*) reportEntries {
NSString* accumulator = [NSString stringWithString:@""];
for (NSString* string in reportEntries) {
NSString* temp = [accumulator stringByAppendingString:string];
accumulator = temp;
if (![string isEqualToString:@"\n"]) {
NSString* temp = [accumulator stringByAppendingString:@";"];
accumulator = temp;
}
}
return accumulator;
}
When I check leaks in Instruments it turns out that many string objects leaked. I managed to isolate the problem to the method above. Can you please help me and point what am I doing wrong?