Re: NSMenuItem addTarget & retain
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