Am I creating a memory leak here?
I have a Cocoa Application and I have set a table view to hold a class (whose contents are written to the hard disk using the "createFileFromSourceDataAtPath" function of the class.
I believe I am creating a memory leak inside the 'for' loop.
Does anyone know how can this be made better? You don't have to see the entire program I think, but if you want, tell me so.
The NSString 'outputFile' is not released inside the for loop... I think it's a memory leak but I'm not sure. Also, the 'outputDirectory' is not released inside the function. Is this too a memory leak? To rectify the possibility of a memory leak, I have tried to add '[outputFile release]' at the end of the 'for' loop, but that caused the debugger to show up and present some errors that I can't explain. Same happened when I tried to put '[outputFile release]' after the loop was over.
What can I do?
I have a Cocoa Application and I have set a table view to hold a class (whose contents are written to the hard disk using the "createFileFromSourceDataAtPath" function of the class.
I believe I am creating a memory leak inside the 'for' loop.
Does anyone know how can this be made better? You don't have to see the entire program I think, but if you want, tell me so.
Code:
-(IBAction)exportSelection:(id)sender
{
unsigned int i;
NSIndexSet *indexSet = [tableView selectedRowIndexes];
NSString *outputDirectory = [exportText stringValue];
printf("output directory: %s",[outputDirectory cStringUsingEncoding:NSUTF8StringEncoding]);
for(i=[indexSet firstIndex]; (i!=NSNotFound); i=[indexSet indexGreaterThanIndex:i]){
NSString *outputFile = [outputDirectory stringByAppendingPathComponent:[[dataContainer objectAtIndex:i]originalName]];
[[dataContainer objectAtIndex:i]createFileFromSourceDataAtPath:outputFile keepOriginalExtension:NO];
}
}
The NSString 'outputFile' is not released inside the for loop... I think it's a memory leak but I'm not sure. Also, the 'outputDirectory' is not released inside the function. Is this too a memory leak? To rectify the possibility of a memory leak, I have tried to add '[outputFile release]' at the end of the 'for' loop, but that caused the debugger to show up and present some errors that I can't explain. Same happened when I tried to put '[outputFile release]' after the loop was over.
What can I do?