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?



SORRY, but I posted misleading information:

I have been misled by an erroneous comment in my code. SetControlPopupMenuHandle does not increase the retain count of the menu. I have stepped past a call to this in the debugger and have proven to myself that the menu retain count is unchanged.

The ReleaseMenu call should not be made, as this will cause the menu to be disposed prematurely.

Sorry.

Douglas

On 8 May 2006, at 16:20, Laurence Harris wrote:

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

// 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,

Yes, but now I'm kind of confused. In this post:

http://lists.apple.com/archives/Carbon-development/2001/Jun/ msg01512.html

Eric says that "you won't need SetControlPopupMenuHandle if you use
SetControlData with kControlPopupButtonOwnedMenuRefTag. They both do the
same thing."


And I have a note in my own records that says:

"pascal void SetControlPopupMenuHandle( ControlRef control, MenuRef menu )
{
OSStatus error;


    error = SetControlData( control, kControlNoPart,
kControlPopupButtonMenuHandleTag, sizeof( menu ), (Ptr)&menu );
    check_noerr( error );
}

-eric"


Do kControlPopupButtonMenuHandleTag and kControlPopupButtonOwnedMenuRefTag
do the same thing?


Larry



_______________________________________________ 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: Laurence Harris <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.