On Jul 7, 2011, at 5:25 PM, Jens Alfke wrote:
> On Jul 7, 2011, at 4:25 PM, Greg Parker wrote:
>> This is less safe than you might like. On iOS and 64-bit Mac, you may end up 
>> with both copies of the class in use simultaneously. That means two separate 
>> invocations of +initialize, two separate locks for @synchronized([MyClass 
>> class]), etc.
> 
> How’s that? I thought there would only ever be one instance of the class 
> loaded at a time.

No, not with the runtime formerly known as "new". 

Internally, ordinary clients of the class use a C symbol to reference the 
class. (This includes [MyClass message] callsites, and subclasses and 
categories of MyClass.) Thanks to two-level symbol linking, each client will 
cleanly link to one copy of the class, even if some other dylib loads another 
copy. The runtime allows any number of copies of the class to exist, but warns 
about the duplicates.

One problem is that there is still only a single global namespace for 
Objective-C classes. Anybody who looks up a class by name may get a different 
copy of the class than the one they would have linked to. I forget whether 
lookup by name is first-copy-wins or last-copy-wins.


-- 
Greg Parker     gpar...@apple.com     Runtime Wrangler


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to