i have a NSMutableArray filled with a lot of lines like this (GPS data, 3600 lines in one hour)
51.040987|12.379154|183|599|0.0|0.0|2014-05-23T17:48:02Z|321.4
In a loop i combine these values to a xml string.
like so
xmlExport = [NSString stringWithFormat:@"%@\t\t<trackpoint>\n\t\t\t<latitude>%@</latitude>\n\t\t\t<longitude>%@</longitude>\n\t\t\t<altitudemeter>%@</altitudemeter>\n\t\t\t<altitudefeet>%@</altitudefeet>\n\t\t\t<speedkmh>%@</speedkmh>\n\t\t\t<speedmph>%@</speedmph>\n\t\t\t<datetime>%@</datetime>\n\t\t\t<degree>%@</degree>\n\t\t</trackpoint>\n", xmlExport,[CoordsArray objectAtIndex: 0], [CoordsArray objectAtIndex: 1], [CoordsArray objectAtIndex: 2], [CoordsArray objectAtIndex: 3], [CoordsArray objectAtIndex: 4], [CoordsArray objectAtIndex: 5], [CoordsArray objectAtIndex: 6], [CoordsArray objectAtIndex: 7]];
and than i want to save this data on device as an xml file, like so
NSString *fileNameCSV = [NSString stringWithFormat:@"%@/export_%@.csv", documentsDirectory, date2];
success = [csvExport writeToFile:fileNameCSV atomically:YES encoding:NSUTF8StringEncoding error:&error];
With fewer data all works fine but when i have about/over 1500 lines i get a memory problem and the app crashes, in simulator all works fine.
The problem is not to save the file, I think more it is in the for loop when combining the xml string.
Is there an other way to save the data to device?
Here my code with autoreleasepool
for (NSString *line in coords) {
@autoreleasepool {
NSArray* CoordsArray = [line componentsSeparatedByString:@"|"];
if(ExportType2==2){
xmlExport = [NSString stringWithFormat:@"%@\t\t<trackpoint>\n\t\t\t<latitude>%@</latitude>\n\t\t\t<longitude>%@</longitude>\n\t\t\t<altitudemeter>%@</altitudemeter>\n\t\t\t<altitudefeet>%@</altitudefeet>\n\t\t\t<speedkmh>%@</speedkmh>\n\t\t\t<speedmph>%@</speedmph>\n\t\t\t<datetime>%@</datetime>\n\t\t\t<degree>%@</degree>\n\t\t</trackpoint>\n", xmlExport,[CoordsArray objectAtIndex: 0], [CoordsArray objectAtIndex: 1], [CoordsArray objectAtIndex: 2], [CoordsArray objectAtIndex: 3], [CoordsArray objectAtIndex: 4], [CoordsArray objectAtIndex: 5], [CoordsArray objectAtIndex: 6], [CoordsArray objectAtIndex: 7]];
}
if(ExportType2==3){
kmlExport = [NSString stringWithFormat:@"%@,%@,%@,%@", kmlExport,[CoordsArray objectAtIndex: 1], [CoordsArray objectAtIndex: 0], [CoordsArray objectAtIndex: 2]];
}
if(ExportType2==4){
gpxExport = [NSString stringWithFormat:@"%@\t\t<trkpt lat=\"%@\" lon=\"%@\">\n\t\t\t<ele>%@</ele>\n\t\t\t<time>%@</time>\n\t\t\t<magvar>%@</magvar>\n\t\t</trkpt>\n", gpxExport,[CoordsArray objectAtIndex: 0], [CoordsArray objectAtIndex: 1], [CoordsArray objectAtIndex: 2], [CoordsArray objectAtIndex: 6], [CoordsArray objectAtIndex: 7]];
}
//NSLog([NSString stringWithFormat:@"line: %@", line]);
//NSLog([NSString stringWithFormat:@"gpxExport: %@", gpxExport]);
}
}
now the app crashes also with few data
self Class MailBuilder 0x00115f58
coords __NSArrayM * @"29 objects" 0x15e5e960
line __NSCFString * @"51.041037|12.379055|0|0|0.0|0.0|2014-05-23T18:29:17Z|297.6" 0x15e497f0
CoordsArray __NSArrayM * @"8 objects" 0x17dde2a0
xmlExport NSString * 0x17d39a00 0x17d39a00