Hard Problem: XCode debugger disconnect

This problem has been killing me. There seems to be a problem with loading files in our release application. When looking at the logs closely one of our theories is that we’re opening too many files. So We decided to test this to determine what the limit is on number of open files.

In the applicationDidFinishLaunching I’m creating a bunch of leaky files like so:
NSLog(@"-----------LOAD LEAKY FILES------------");
NSFileManager *filemgr;

filemgr = [NSFileManager defaultManager];
@try {
    for(int i = 0; i < 1100; ++i) {
        NSString* iToString = [NSString stringWithFormat:@"assets/%d", i];
        NSString* assetPath = [[NSBundle mainBundle] pathForResource: iToString ofType:@"png"];
        FILE *f = fopen([assetPath cStringUsingEncoding:1], "r");
        if(f == NULL)
            NSLog(@"%@", [assetPath stringByAppendingString:@" not found"]);
            NSLog(@"%@", [assetPath stringByAppendingString:@" found"]);
@catch (NSException *exception) {
    NSLog(@"%@", exception.reason);
@finally {

Once the application fully loads, I proceed to do clean file I/O that simulates production. This will open an image, close and image etc… While we haven’t figured out what the file limit is; XCode will eventually disconnect and the application gets minimized. As a result we get no error logs to look at and aren’t able to make any headway.

I have a general exception breakpoint set but nothing hits it. Really struggling to figure out how to debug this problem.

I am not sure if you have a Mac OS application.

But if you do, try running the application from the command line and directing its output to a log file. This way, you can go and check the log file when the application dies.

Also, if you open a second terminal window, you can observe the changes in the log file while the application is running by using the tail command with the -f option.

I apologize if I wasn’t clear. This is an iOS application.

I’m not sure how to tail active logs on the device outside of xcode or pull system logs from the device the way you can with Android adb logcat.

Then, here is an ad hoc way.

Count the number of files opened and write the value of the counter to a file. Next time you start the application, open the file and check the count.

Resolved thank you :slight_smile: