Le 17 avr. 2010 à 16:16, Ken Thomases a écrit :

> On Apr 17, 2010, at 8:53 AM, Paul Sanders wrote:
> 
>> Something I've never been clear about though is 
>> where an object's retain count is stored.  This obviously 
>> requires an iVar somewhere (in addition to isA), so there might 
>> be a trap for the unwary there [...]
> 
> My understanding, which is vague and for which I have no references, is that 
> it's handled in a manner similar to what was recently exposed via the 
> associated references API (i.e. objc_setAssociatedObject and friends).
> 
> That is, retain counts are stored outside of the instance.
> 
> Having just looked up the source for CFRelease, I can't say my understanding 
> has increased.  ;)  Although, there is confirmation there that the retain 
> count is at least sometimes held externally.
> 
> Would be an interesting subject for Mr. Bumgarner to expound upon on his blog.
> 

AFAIK, CF objects store the retain count in an "ivar" (or a struct field to be 
exact) and  standard Obj-C objects ref count is stored in an external hash 
collection (CFBasicHash on 10.6). 

You can see that by calling NSIncrementExtraRefCount() and stepping though the 
call using GCC.

That said, this is an implementation details.

IIRC, GnuStep used to store the retain count in 4 additional bytes allocated 
before each object.

uint32_t *rc = (uint8_t *)self - 4;


-- Jean-Daniel




_______________________________________________

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