Re: Crash with ARC enabled on Xcode 6.1
Re: Crash with ARC enabled on Xcode 6.1
- Subject: Re: Crash with ARC enabled on Xcode 6.1
- From: Greg Parker <email@hidden>
- Date: Thu, 23 Oct 2014 15:06:28 -0700
> On Oct 23, 2014, at 2:18 AM, Kevin Meaney <email@hidden> wrote:
>
> From what I understand any code that is executed before main is called is done so before the objective-c runtime is fully setup which means you have no guarantees about what will work. In objective-c++ where you can create static C++ objects that results in objective-c being called it is an easy way to make difficult to track crashes.
The situation is much more favorable than that. Problems with Objective-C initialization are uncommon.
The initialization order is generally like this:
1. Everything in libraries you link to is initialized.
2. Your classes' +load methods run. Each class runs +load before its subclasses. (Timing of category +load is more complicated, but in most cases they also run now.)
3. Your C and C++ static constructors run.
4. main()
Any of your code can use anything from libraries it links to without fear. Those libraries should be completely ready to go when your code runs.
C/C++ static initializers can call Objective-C code without fear. (Note that if your C/C++ static initializers call your own Objective-C code which has its own C/C++ static initializers inside then you still have to worry about the traditional "static initialization order fiasco". Objective-C does not make that problem better or worse.)
Objective-C +load methods need to be the most careful because they run before the C/C++ static initializers in the same executable or even in the same source file.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden