PDA

View Full Version : Outline of what Apple does when your app is launched?




GorillaPaws
Oct 25, 2009, 08:42 PM
I'm wondering if there's a resource where you can see exactly what happens when your app launches. I have a rough idea about several of the big steps (applicationDidFinnishLaunching, awakeFromNib etc.), but I would love to find an article/reference that goes literally step-by-step through the process of all the initial setup in a standard cocoa app.

The reason I started thinking about this is I've been reading "Cocoa Design Patterns" which is quite excellent. In the notifications chapter I came across the line:

Every thread in a Cocoa application has a default notification queue

It made me realize that there must be dozens of other objects that Apple is creating for me that I have know idea exist, and it would be interesting to see exactly what gets created when in the timeline. Does anyone know of a resource that documents this process?



Cromulent
Oct 26, 2009, 03:01 AM
The simplest method to finding out what is being run below your application code is to just get the debugger out and step into some Cocoa functions. Eventually you'll get down to the C level stuff and then into Assembly.

Frankly I was amazed when I compared some C programs with a test Objective-C program and the amount of crap that gets run behind the scenes.

Catfish_Man
Oct 26, 2009, 09:56 AM
Somewhat easier than just stepping through things in gdb would be to use dtrace and/or Instruments to watch calls and allocations.

lee1210
Oct 26, 2009, 10:17 AM
The first, and likely only, thing you do in your main function in a Cocoa app is call NSApplicationMain:
http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Miscellaneous/AppKit_Functions/Reference/reference.html#//apple_ref/c/func/NSApplicationMain

From there, the most "interesting" piece is loading of the main nib. This page has some information about what happens when you do this:
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html#//apple_ref/doc/uid/10000051i-CH4-SW8

Stepping through things, watching calls, etc. will certainly be of value/interest but i thought it might be of value to read the documents that detail the process so you have some of the high-level knowledge about the design as well as the low-level knowledge of the actual calls that go on.

-Lee

GorillaPaws
Oct 28, 2009, 07:03 PM
Thanks for your replies. I was hoping there'd be more info/easier to access than using dtrace or the debugger. I also found this article (http://cocoawithlove.com/2008/03/cocoa-application-startup.html) which didn't have all the detail I was hoping for but was helpful as a general overview. Hopefully someone finding this thread in a search will find it useful.