how to create a NSMenuItem without memory leaks
how to create a NSMenuItem without memory leaks
- Subject: how to create a NSMenuItem without memory leaks
- From: Martin Batholdy <email@hidden>
- Date: Tue, 17 May 2011 01:04:54 +0200
Hi,
I create an NSMenu by myself;
menu = [[NSMenu allocWithZone:menuZone] init];
And depending on some data NSMenuItems get created.
Now these menuItems get deleted and redrawn depending on some actions of the user with
[menu removeItemAtIndex: x];
I create the menu items like this:
newItem = [[NSMenuItem alloc] init];
[newItem initWithTitle:aTitle
action:@selector(show:)
keyEquivalent:@""];
[menu addItem:newItem];
Now is this a memory leak?
Because I don't release it anywhere. However the menu sometimes gets updated.
So this code ([[NSMenuItem alloc] init]) is invoked several times without a release call anywhere.
Is this better:
NSMenuItem *newItem = [menu addItemWithTitle:aTitle action:@selector(show:) keyEquivalent:@""];
...
since I don't own newItem it should get autoreleased, right?
_______________________________________________
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