• 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 14:13:25 -0800

On Dec 24, 2009, at 12:47 AM, Ken Thomases wrote:
> On Dec 24, 2009, at 2:23 AM, John Engelhart wrote:
>>
>> Wait, what?  I could understand that under GC -retain might be nothing more
>> than the equivalent of "- (id)retain { return(self); }", but -retainCount?
>> Is it really "- (NSUInteger)retainCount { return((NSUInteger)self); }" ?
>> Wouldn't it make more sense to just return 1, or maybe something like
>> NSUIntegerMax?
>
> There is no implementation of -retainCount under GC.  There's a short-circuit in obj_msgSend that detects the selector for the memory management methods which are no-ops.  Since -retain and -autorelease have to return self, that's what the short-circuit does.  -retainCount gets the same treatment and so the same return value.  The return value doesn't matter, anyway.  (Frankly, it hardly matters under managed memory, either.)

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.

Don't write any code that relies on those selectors being equal, though. It will change in the future.


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

  • Follow-Ups:
    • Re: Releasing Objects
      • From: Sherm Pendley <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>)

  • Prev by Date: Re: NSCollectionView NSArrayController bindings from outer hell
  • Next by Date: MallocDebug Hang with Core Data Save
  • Previous by thread: Re: Releasing Objects
  • Next by thread: Re: Releasing Objects
  • Index(es):
    • Date
    • Thread