Terminating the ApplicationMacApp 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
ExitToShellToolbox trap so that the call goes to the
ExitToShellCleanupMacApproutine. That routine gets the trap address for
CleanupMacApp, then calls
ExitToShell, terminating the application.
CleanupMacApproutine first unpatches the
ExitToShellpatch. It then calls
gApplication->Terminate, giving the application a chance to do any special cleanup before it relinquishes control. Patching
gApplication->Terminateis called, even if a user forces the application to quit. The
CleanupMacApproutine 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.
Terminatemethod is implemented in
TEventHandler, but does nothing in that implementation. Your application class can override
Terminateif it needs to do any special cleanup.