Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Who releases a MenuRef of a popup menu control?



On 5/8/06 11:01 AM, Douglas Norton didst favor us with:

> On 8 May 2006, at 15:49, Norio Ota wrote:
> 
>> I am about to attach a menu reference created programmatically to a  popup
>> control. Is the menu reference freed when the control is disposed?
> 
> yes
> 
>> Or do I have to release it by myself?
> 
> and yes.
> 
> 
> MenuRef rMenu = NewMenu(...)        // retain count = 1;
> 
> SetControlPopupMenuHandle( hControl, rMenu );  // retain count = 2

Here is what my testing just now shows in 10.3.9:

ItemCount    ic = GetMenuRetainCount( menu );
// ic is 1
SetControlPopupMenuHandle( inPopup, menu );
ic = GetMenuRetainCount( menu );
// ic is still 1

SetControlData ( inPopup, kControlEntireControl,
kControlPopupButtonMenuRefTag, sizeof( MenuRef ), &menu );

and

SetControlData ( inPopup, kControlEntireControl,
kControlPopupButtonOwnedMenuRefTag, sizeof( MenuRef ), &menu );

both produce the same result as well.

Larry

> 
> // don't forget these
> // SetControlMinimum( hControl, 0 );
> // SetControlMaximum( hControl, CountMenuItems( rMenu ) );
> 
> ReleaseMenu( rMenu ) // retain count = 1
> 
> 
> ...
> ...
> ...
> ...
> // later when window / dialog disposed of
> 
> // Either
> DisposeWindow( win );  // tears down controls in window
> // or
> DisposeControl( hControl )  // => Control releases menu, retain count
> = 0, menu dies.
> 
> 
> Hope that helps,
> 
> Douglas
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Carbon-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/carbon-dev/email@hidden
> 
> This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden

References: 
 >Re: Who releases a MenuRef of a popup menu control? (From: Douglas Norton <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.