Below is a menu handling routine that leaks.  I've been reading the recent
threads on MenuDispose and I need clarification on a couple of issues.

Since each form has only one menu, I'm assuming that I don't need to call
any menu initialization code (including MenuDispose()).  I'm basing that on
the tutorial, p.67, 

        "The resource for the Main form was modified to include setting
        the menu resource ID to the ID of the menu bar resource. As a re-
        sult, the default form-event processing routine,
        FrmHandleEvent (called internally by FrmDispatchEvent)
        can handle setup and teardown of the menu for a form. As a re-
        sult, SetCurrentMenu is no longer required, because
        FrmSetActiveForm handles this task automatically."

Grepping the Palm sample code for MenuDispose, MenuInit or
MenuGetActiveMenu turns up only one example, the one in Phase 2 of the
tutorial.

What's got me worried is that calling the FrmHelp routines below seems to
cause a leak roughly equivalent to the size of the text in the string of
the FrmHelp dialogue called (by an eyeball's guess).

I get the feeling that I'm missing something completely obvious.
---------------------------------------------------
static Boolean AllViewDoMenuCommand( Int command )
{
        #if ERROR_CHECK_LEVEL == ERROR_CHECK_FULL
                DWord startFreeDynamicMemory, endFreeDynamicMemory, junk;
                Err err = MemHeapFreeBytes( 0, &startFreeDynamicMemory, &junk);
        #endif 

        Boolean bHandled = false;
        FormPtr frm;

        switch (command)
        {
            case OptionsHelp:
                        FrmHelp( HelpInfoString );
                        bHandled = true;
                        break;

                case OptionsPreferences: // Display the prefs form
                        FrmGotoForm( PrefFORMForm );
                        bHandled = true;
                        break;

            case OptionsRegistration:
                        FrmHelp( RegistrationInfoString );
                        bHandled = true;
                        break;

                case OptionsCancelSnoozeAlarm:
                        CancelAllSnoozes();
                        bHandled = true;
                        break;

                case OptionsAbout:              // Display the info form.
                        // Load the info form, then display it.
                        frm = FrmInitForm( AboutFORMForm );
                        FrmDoDialog( frm );
                        FrmDeleteForm( frm );
                        bHandled = true;
                        break;

                default:
                        break;
        }
#if ERROR_CHECK_LEVEL == ERROR_CHECK_FULL
        MemHeapFreeBytes( 0, &endFreeDynamicMemory, &junk);
        ErrNonFatalDisplayIf ( startFreeDynamicMemory != endFreeDynamicMemory,
        "Memory Leak!");                
#endif          
        
        return (bHandled);
}
---------------------------------------------------

Have I made some horrendous mistake in my leak checking?  Or is the help
form not disposed of until some later point?
--
Andrew Ball
[EMAIL PROTECTED]

Reply via email to