tags:

views:

33

answers:

1

My app takes too much time to loading. So I put a NSLog in main() function like this to measure loading time from first:

int main(int argc, char *argv[]) 
{    
    NSLog(@"main");

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

But, the log displayed at really later time. Default.png displayed about 5 seconds, all loading process completed in 1~2 seconds after log appeared.

What's happening before executing main() function on iPhone app?

+4  A: 

The entry point of a binary is not main(), but start. This is true for most binaries compiled with gcc. When there are static variable constructors in C++, or functions with __attribute__((constructor)) attribute, or +load methods, they will be run before main().

Some code will run even before start, because of dynamic linking. The dyld is responsible for this. All undefined external symbols are filled in at this point. And of course, the initializers of these libraries will execute.

The Default.png is shown by SpringBoard, and is not controlled by your app. Thus there can be a time delay between the Default.png is shown, and code is actually running.

These actions, however, are fast. The delay is more likely introduced by attaching to the remote gdb and Xcode.

KennyTM
Wow cool. Thanks!
Eonil