Important: The information in this document is obsolete and should not be used for new development.
Terminating the Application
MacApp includes a general-purpose mechanism for patching Toolbox traps, described in"Trap Patching," beginning on page 82. That mechanism is used to guarantee the application has a chance to perform necessary cleanup, even when it is terminated abnormally.During initialization, MacApp uses its trap-patching mechanism to patch the
ExitToShell
Toolbox trap so that the call goes to theExitToShellCleanupMacApp
routine. That routine gets the trap address forExitToShell
, callsCleanupMacApp
, then callsExitToShell
, terminating the application.The
CleanupMacApp
routine first unpatches theExitToShell
patch. It then callsgApplication->Terminate
, giving the application a chance to do any special cleanup before it relinquishes control. PatchingExitToShell
ensures thatgApplication->Terminate
is called, even if a user forces the application to quit. TheCleanupMacApp
routine finally frees various items and unpatches any other traps the application has patched, a service that is likely to make your application popular with other programs.The
Terminate
method is implemented inTEventHandler
, but does nothing in that implementation. Your application class can overrideTerminate
if it needs to do any special cleanup.