• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Releasing Objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Releasing Objects


  • Subject: Re: Releasing Objects
  • From: Greg Parker <email@hidden>
  • Date: Thu, 24 Dec 2009 21:43:13 -0800

On Dec 24, 2009, at 3:16 PM, Sherm Pendley wrote:
> On Thu, Dec 24, 2009 at 5:13 PM, Greg Parker <email@hidden> wrote:
>>
>> More precisely, there's exactly one short-circuit check and thus only one selector value. Under GC, @selector(retain) == @selector(release) == @selector(autorelease) == @selector(dealloc) == @selector(retainCount). Happily, `return self` works to implement all of those.
>
> Just out of curiosity, is that really a short-circuit in the
> message-passing machinery, or are all those selectors simply
> registered to point to the same IMP function? A useless bit of
> knowledge for us end-users, I know, but interesting just the same.

Both. There are an extra two instructions at the start of most flavors of objc_msgSend(). That's intended to do nothing fast. The method lookup machinery also recognizes that selector value, and hands back a `return self` IMP. That's for the benefit of code that looks up IMPs and calls them directly.

The second half was missing at one point during Leopard development. Some code was looking up IMPs for -retain and -release. But under GC the methods named above share the same selector value, so the runtime handed back the first method in the class's method list with that selector. For most classes this is the -dealloc implementation. Hilarity ensued.


--
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

References: 
 >Releasing Objects (From: Michael Craig <email@hidden>)
 >Re: Releasing Objects (From: Franck Zoccolo <email@hidden>)
 >Re: Releasing Objects (From: Bill Bumgarner <email@hidden>)
 >Re: Releasing Objects (From: John Engelhart <email@hidden>)
 >Re: Releasing Objects (From: Ken Thomases <email@hidden>)
 >Re: Releasing Objects (From: Greg Parker <email@hidden>)
 >Re: Releasing Objects (From: Sherm Pendley <email@hidden>)

  • Prev by Date: IPhone- Datasensitive bug from CoreData...
  • Next by Date: Re: IPhone- Datasensitive bug from CoreData...
  • Previous by thread: Re: Releasing Objects
  • Next by thread: Re: Releasing Objects
  • Index(es):
    • Date
    • Thread