Skip navigation.
 
mlRe: Race in Apple's NSTreeContoller/NSOutlineView
FROM : Jens Alfke
DATE : Sun Jun 22 17:57:15 2008

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

Related mailsAuthorDate
mlHelp debugging why NSOutlineView stops updating Godfrey van der Li… Jun 20, 00:13
mlRace in Apple's NSTreeContoller/NSOutlineView Godfrey van der Li… Jun 20, 04:49
mlRe: Race in Apple's NSTreeContoller/NSOutlineView Conrad Taylor Jun 20, 06:17
mlRe: Race in Apple's NSTreeContoller/NSOutlineView Godfrey van der Li… Jun 21, 09:44
mlRe: Race in Apple's NSTreeContoller/NSOutlineView John C. Randolph Jun 21, 12:03
mlRe: Race in Apple's NSTreeContoller/NSOutlineView Chris Hanson Jun 22, 03:59
mlRe: Race in Apple's NSTreeContoller/NSOutlineView Jens Alfke Jun 22, 17:57
mlRe: Race in Apple's NSTreeContoller/NSOutlineView Ron Lue-Sang Aug 16, 05:40