Resources | Resources |



FreeAppData function

When an application closes, it needs to free any resources it has allocated. The C Application Wizard creates an empty FreeAppData function that contains comments showing how to release interfaces, as shown below.

void basic_app_test_FreeAppData(basic_app_test * pMe)
    // Insert your code here for freeing any resources you have allocated...

    // Example to use for releasing each interface:
    // if ( NULL != pMe->piMenuCtl ) {     // check for NULL first
    //     IMenuCtl_Release(pMe->piMenuCtl)// release the interface
    //     pMe->piMenuCtl = NULL;          // set to NULL so no problems later
    // }

Applications need to release all interfaces they have obtained and all memory they have allocated. In general, all interfaces or memory allocated in the application's InitAppData function should be matched with their release functions in the FreeAppData.

In this example from c_basicapp, the application has not instantiated any interfaces, so it only needs to release the image it has loaded.

void MyApp_FreeAppData(MyApp * pMe)
   // Release the image pointer:
   if (pMe->piImage != NULL) {  
      IImage_Release (pMe->piImage); 
		 pMe->piImage = NULL;