• 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: menu madness with retain count
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: menu madness with retain count


  • Subject: Re: menu madness with retain count
  • From: Jens Alfke <email@hidden>
  • Date: Tue, 27 Apr 2010 11:42:24 -0700


On Apr 27, 2010, at 8:28 AM, Bill Appleton wrote:

1) after i append an item i have created to a menu i have created, and i
don't want to own the menu item any more, i should release the item so that
the menu owns it

Don't think of who "owns" an object. The memory model doesn't work that way — the whole point is that multiple objects can have references to another object without any of them having to be in charge of the referenced object's lifespan.


What you "own" are references. If you call a method that creates a reference, like +alloc, -retain or -copy, then you now own a reference to that object. For as long as you own that reference, the object will stay around. When you don't need the object anymore, you have to release that reference by telling the object to -release or - autorelease.

[And +1 on ignoring -retainCount. The only time this method is useful is if you are in gdb debugging some kind of tricky refcounting error; and even then you have to take its value with a grain of salt due to the effect of the autorelease pool.]

—Jens_______________________________________________

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: menu madness with retain count
      • From: vincent habchi <email@hidden>
References: 
 >menu madness with retain count (From: Bill Appleton <email@hidden>)
 >Re: menu madness with retain count (From: Graham Cox <email@hidden>)
 >Re: menu madness with retain count (From: Bill Appleton <email@hidden>)

  • Prev by Date: Re: Fastest way to check for descendants of an object
  • Next by Date: iPhone development without using the Xcode IDE
  • Previous by thread: Re: menu madness with retain count
  • Next by thread: Re: menu madness with retain count
  • Index(es):
    • Date
    • Thread