Re: menu madness with retain count
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