Re: Race in Apple's NSTreeContoller/NSOutlineView
Re: Race in Apple's NSTreeContoller/NSOutlineView
- Subject: Re: Race in Apple's NSTreeContoller/NSOutlineView
- From: Jens Alfke <email@hidden>
- Date: Sun, 22 Jun 2008 08:57:15 -0700
FYI, another source of weird inconsistently-manifesting bugs involving
nib loading: The objects in the nib are sent -awakeFromNib messages in
a somewhat random order. The order is often the same from one run to
the next on a single machine, but can vary between machines, or after
seemingly unrelated changes to the code.
What I've seen happen in my code is that object A's -awakeFromNib
method calls another object B in the nib, and the method that's called
relies on object B's -awakeFromNib already having run. So it works if
B was awoken before A, but fails if B hasn't been awoken yet.
(The reason for the random order? The objects in the nib are stored in
an NSSet, and the nib loader enumerates over that set sending each
object -awakeFromNib. The order of enumeration of a set or dictionary
is undefined and depends on the internal ordering of the objects in
the hashtable, which in turn depends on the object's -hash codes. And
NSView's -hash method, inherited from NSObject, returns ... its
pointer value cast to an integer. So in short, the order in which the
objects are sent -awakeFromNib is dependent on on their in-memory
layout, and that depends on undefined details of the order in which
all the allocations in the heap occurred and the sizes of those
blocks. Things like that are very dependent on machine architecture
and the timing of multiple threads.)
More than you wanted to know, I'm sure...
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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