Resources | Resources |



Special considerations for application shutdown

When an application has shut down, and Brew MP has released the application's primary AEEApplet structure, Brew MP also releases any remote objects that still hold references to application objects and frees any memory allocated by the application that has not yet been freed (which is typically reported as a memory leak).

Applications can use local objects and remote objects (such as objects in services). An example of remote objects is the use of windows through Window Manager. Applications need to free resource properly to avoid problems during application shutdown. If this is not done properly, one problem that can occur during the shutdown process is that code within the application module may be called after the AEEApplet structure has been released (the application is no longer running). For example, if an application has a window that was still active when the application shutdown, the Window Manager sends the WM_STATUS_CLOSE event to the window (usually a RootContainer widget used to create it) and releases its final reference. In handling this event or the following release, custom handlers or code that belongs to the application may be called, which causes errors.

To avoid prematurely releasing objects or referring to local objects that are no longer available, such as the AEEApplet structure, the following guidelines are recommended:

  • Clean up any references application-owned objects may have to the AEEApplet structure before returning from pFreeAppData execution. Any references that remain after the application has returned from this function are invalid, and can result in undefined behavior if used afterwards.
  • Only release references to objects that the application or application-local objects maintain. For example, widgets created by the application should only be released as many times as they were referenced (Created, QueryInterface'd, or AddRef'd). Calling Release() more than this, such as in a loop until the widget is completely released, is dangerous if any of those references are owned by remote objects or services (such as Window Manager).