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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to