contentsOfDirectoryAtPath: result causes memory issue and app crashes

one of our clients stored to many files as it seems.


following CODE:


+(NSArray *)setDirContent

{ //load Content of User Directory in file

NSDate *logFileDate = [NSDate date];

NSString *dirCont = [NSString stringWithFormat:@"%@ created: %@\n\n",DIRCONTENT,logFileDate];

NSString *resourcePath = [self getSystemDirectory];

NSError *error;

NSFileManager *fileManager = [NSFileManager defaultManager];

NSArray *directoryContents = [fileManager contentsOfDirectoryAtPath:resourcePath error:&error];

for (int i=0;i<directoryContents.count;i++)

{

dirCont = [NSString stringWithFormat:@"%@,\n%@",dirCont,directoryContents[i]];

}

NSString *statFilePath = [NSString stringWithFormat: @"%@%@%@",[self getClientDirectory],DIRCONTENT,TXTFILE];

NSData *fileContent = [dirCont dataUsingEncoding:NSUTF8StringEncoding];

NSFileHandle *handle;

handle = [NSFileHandle fileHandleForWritingAtPath: statFilePath];

[fileManager createFileAtPath: statFilePath contents:fileContent attributes:nil];

return directoryContents;

}


READS the directory content and stores it into a file.


but since a few weeks for one client the app can not execute this code any longer because the app crashes.


What could we do to get the content of the directory into a file?


Thanks for your ideas !

Replies

since a few weeks for one client the app can not execute this code any longer because the app crashes.

What platform is this on? And what does the crash look like? If you can post an Apple crash report, that’d be ideal. Use the

<>
button to format it as text.

For more info about crash reports, see Technote 2151 Understanding and Analyzing iOS Application Crash Reports.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"