• 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: why does this leak?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: why does this leak?
      • From: Robert Dell <email@hidden>
References: 
 >why does this leak? (From: Robert Dell <email@hidden>)

  • Prev by Date: Orange County Cocoa-heads conflicts with major holiday, film at 11!
  • Next by Date: Accessing IBOutlet From non-IBAction Method
  • Previous by thread: Re: why does this leak?
  • Next by thread: Re: why does this leak?
  • Index(es):
    • Date
    • Thread