I am simple exporting my data into CSV file. But when I click on Export Button, Leak Instrument shows [NSPlaceholderMutableString init] error.
I have not used Placeholder anywhere in my NSMutableString, then What’s so wrong that Instrument shows Leak.
Here is my code:
- (IBAction)btnExportDataPressed:(id)sender
{
csvString = [[NSMutableString alloc] init];
csvString = [NSMutableString stringWithFormat:@"No.,Name,Type,MaskPAN,SwipeTime\n"];
NSString *msg = @"";
if (self.totalCards.count>0)
{
for (int i=0; i<self.totalCards.count; i++)
{
self.cardInfo = [self.totalCards objectAtIndex:i];
[csvString appendString:[NSMutableString stringWithFormat:@"%d,%@ %@,%@,%@,%@\n",i+1,self.cardInfo.firstName,self.cardInfo.lastName,self.cardInfo.type,self.cardInfo.maskedPAN,self.cardInfo.swipeTime]];
}
NSLog(@"csvString:%@",csvString);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName = [NSString stringWithFormat:@"ORANGE_BOWL_%@",[NSDate date]];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.csv",fileName]];
[fileManager createFileAtPath:fullPath contents:[csvString dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
msg = @"Data exported successfully. Connect the device to iTunes to get the records.";
}
else
{
msg = @"No Data to Export";
}
[csvString release];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Discover Orange Bowl," message:msg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
Below is error pic from Instrument

There’s a memory leak right at the top of your code:
So you’re allocating memory for a mutable string (line 1) which inceases the retain count by 1, and then in line 2 you lose your pointer reference to that because you assign another string to the pointer. This will leak memory for sure; not sure if the rest of your code is doing anything else bad.
So delete the first line — it’s useless and only serves to cause a memory leak.
Also, your
[csvString release]line looks wrong because when you last assigned something tocsvstringyou used[NSMutableString stringWithFormat]which doesn’t increase the retain count (and hence you shouldn’t decrease it by usingrelease). So try removing the line that says[csvString release];.The Leaks tool can show slightly baffling references to object you didn’t actually use; this is caused by these objects being used internally by objects that you did use (and leak).