Re: earliest code that runs?
Re: earliest code that runs?
- Subject: Re: earliest code that runs?
- From: Glenn Andreas <email@hidden>
- Date: Wed, 28 Jul 2004 09:22:30 -0500
At 12:33 AM -0700 7/28/04, James DiPalma wrote:
On Jul 27, 2004, at 6:08 PM, Matt Neuburg wrote:
I was assuming that a class's +initialize method would be called before any
instance's init method, but no. (I thought that because an example in the
docs seemed to imply it.)
As mmalc points out, for a given class, +initialize should get
called before any method on that class or its instances gets called.
No?
The runtime is responsible to making sure that this happens - there
is a flag (CLS_INITIALIZED) on a class that is checked when a message
is sent - if it is cleared, +initialize is called before that message
is sent (and then the flag is set).
Note that this will not be called before another class method (since
that would be looking for the meta-class "has been initialized" bit),
which is very important, since +load is called before +initialize.
+initialize should also be sent to all super-classes before being
sent to any of the subclasses - if a subclass does not implement
+initialize, the super-classes +initialize method will get called a
second time.
For more gory details, see the routine class_initialize in
objc-class.m in the Darwin runtime (it gets ugly when you toss in
threading, and the fact that something may already be initializing on
a separate thread).
--
Glenn Andreas email@hidden
mondo blobbo, Cythera, Theldrow, oh my!
Mad, Bad, and Dangerous to Know
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.