On Apr 27, 2010, at 7:46 AM, Bill Appleton wrote:

> i like to create some menus, set them as the main menu bar, then maybe
> delete them, and create some more menus, use them, etc.
> 
> but i can't find any way to do this with cocoa
> 
> here is the problem
> 
> when you add a submenu (setSubMenu:forItem) the retain count on the submenu
> goes up by one
> 
> but when you delete that item, or set its submenu to nil, the retain count
> does not change
> 
> if you ever delete a menu that has a submenu you will get a crash, but there
> is no way to unassociate the menu and the submenu
> 
> another problem: when you set the main menu bar  [NSApp setMainMenu:themenu]
> the retain count on themenu goes up by a lot, i can't predict it, but maybe
> 4 or 5
> 
> if you set the main menu bar to nil the retain count does not change on the
> original main menu
> 
> so given all this, i can't find a way to create and delete menus without
> crashes or memory leaks
> 
> am i doing something wrong?

Don't pay attention to retain counts. They rarely indicate anything useful. For 
instance, in your first case, how do you know that the menu hasn't autoreleased 
the submenu? -autorelease does not decrement the retain count, but promises 
release later on. Check after the runloop has run--you may see different 
results.

As far as crashing when removing a menu with a submenu, that shouldn't happen. 
Chances are, it is your code that is causing the crash (I say this from 
personal experience). Otherwise it is one nasty bug.

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

_______________________________________________

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