Re: menu madness with retain count
Re: menu madness with retain count
- Subject: Re: menu madness with retain count
- From: Uli Kusterer <email@hidden>
- Date: Tue, 27 Apr 2010 23:26:13 +0200
On 27.04.2010, at 17:28, Bill Appleton wrote:
> 1) after i append an item i have created to a menu i have created, and i
> don't want to own the menu item any more, i should release the item so that
> the menu owns it
Depends on how you create the item. If you create them in a way that you have to release it, you have to release it. As soon as you add it to a menu, that menu will retain it or copy it if it wants to keep it around, and you can release your reference to it. If you create the item autoreleased (e.g. using a factory method), of course you don't release it.
> 2) when i add a submenu i have created to a menu i have created, and i don't
> want to own the submenu any more, i should release the submenu so that the
> menu owns it
Same as with menu item. If you create it so you own it, you release it once *you* are done with it. Everyone else (including the menu item whose submenu you set it as) will retain it or copy it if they want to keep it around.
> 3) when i set the menus i have created for NSApp using setMainMenu then...
> what? who owns them? how do i set more menus for NSApp? how do i get NSApp
> to release the current set?
Again, the application will retain the menu you give it as the main menu (and that in turn will retain all its items, which in turn will retain their submenus which will retain their items which...) and if you created it so you have to release it, you ca release it once you don't need it anymore.
To get the shared application singleton to release its main menu, you'll have to set a different main menu. You might be able to set the main menu to NIL, or you may have to create a minimal main menu (with an application menu), but that's pretty much it.
If you have problems changing the main menu, I'd suggest leaving the main menu and the application menu the same, and just editing the main menu by adding/deleting menu items and submenus. Messing with the main menu like that seems to be one of the less explored areas of MacOS X. Also, keep in mind that, at least on 10.5 and later, you can hide menu items (and thus menus) if you find that recreating a "special" menu doesn't make it special anymore.
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
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