Re: why does this leak?
Re: why does this leak?
- Subject: Re: why does this leak?
- From: Charlton Wilbur <email@hidden>
- Date: Mon, 13 Feb 2006 19:51:37 -0500
On Feb 13, 2006, at 6:41 PM, Robert Dell wrote:
I update my menus by first removing the items. I used the
following code:
while ([mySingMenu numberOfItems] > 0)
{
[mySingMenu removeItemAtIndex: 0];
};
From what i was told on this list, removing items from the list
automatically releases them. why is it i get 2 leaks per remove
without a predeclared release as such?
How do you know you're getting "2 leaks per remove"? If you're
paying attention to [object retainCount], DON'T. All sorts of other
objects in the Cocoa framework may send retain messages to your
objects; all you need to worry about is whether *you* have sent a
balanced number of alloc/copy/retain and release/autorelease
messages. In the case of collections which retain their member
objects, you still have to pair retains and releases; it's just that
adding the object to the collection *also* retains it, and removing
it *also* releases it.
Further, I see nothing in the documentation that indicates that -
[NSMenu addItem:] sends a retain message, or -[NSMenu
removeItemAtIndex:] sends a release message. If you compare this to
the documentation for -[NSMutableSet addObject:] and -[NSMutableSet
removeObjectAtIndex:],for instance, you'll see that both of the
latter are explicitly documented to send retain and release messages,
respectively. I suspect you're confusing the behavior of NSMenu with
the behavior of NSMutable(Set|Array|Dictionary).
Charlton
--
Charlton Wilbur
email@hidden
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden