• 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: NSMenuItem addTarget & retain
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMenuItem addTarget & retain


  • Subject: Re: NSMenuItem addTarget & retain
  • From: Graham Cox <email@hidden>
  • Date: Thu, 6 Aug 2009 14:59:08 +1000


On 04/08/2009, at 6:46 PM, Remko Tronçon wrote:

Foo* foo = [[Foo aloc] init];
NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"Item" action:
@selector(action:) keyEquivalent: @""];
[item setTarget: foo];
[foo release];

Unless I have a problem in some other part of my code, it seems that
releasing the 'foo' object is not allowed. In my limited knowledge of
Cocoa, I would expect that NSMenuItem retains foo. Is this a wrong
assumption?


Yes, NSMenuItem does not retain its target.

From the docs: "Control objects do not (and should not) retain their targets. However, clients of controls sending action messages (applications, usually) are responsible for ensuring that their targets are available to receive action messages. To do this, they may have to retain their targets in memory-managed environments. This precaution applies equally to delegates and data sources."

file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html


--Graham


_______________________________________________

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: NSMenuItem addTarget & retain
      • From: Remko Tronçon <email@hidden>
References: 
 >NSMenuItem addTarget & retain (From: Remko Tronçon <email@hidden>)

  • Prev by Date: Mac OS X 10.5.8 update breaks tokenize function in -[NSXMLNode objectsForXQuery:error:]
  • Next by Date: Re: Generating random numbers
  • Previous by thread: NSMenuItem addTarget & retain
  • Next by thread: Re: NSMenuItem addTarget & retain
  • Index(es):
    • Date
    • Thread