Resources | Resources |



Memory leak detection

When an application exits, Brew MP searches the heap for heap nodes marked with the application's 32-bit ID. When such a node is found, Brew MP reports the memory leak with an appropriate debug message and frees the corresponding allocated memory. Brew MP defers memory leak detection until the last application in a module exits.

Note: Brew MP does not call a destructor such as IInterfaceName_Release() or MyClass_Release() if the heap node is a memory allocation for a Brew MP Interface or an extension class, respectively. For example, if an application invoked ISHELL_CreateInstance() or MyClass_CreateInstance() but forgot to call IInterfaceName_Release() or MyClass_Release().

For example:

*AEEModule.c 00266 Warning -- memory leak, freeing, 0xABCD1010, NONAME, size 328

This log message indicates there is a memory leak of 328 bytes from memory address 0xABCD1010. The source of the memory is NONAME because heap debugging was not enabled, which allows the memory block to be tagged with a file name and a line number.

To enable heap debugging, define AEE_DBG_HEAP to be 1 in the source file before AEEStdLib.h is included. For example:

#define AEE_DBG_HEAP 1
#include "AEEStdLib.h"

When heap debugging is enabled, the log message includes the file name and line number when a leak is detected by Brew MP. For example:

*AEEModule.c 00266 Warning -- memory leak,freeing, 0xABCD1010, .\myapp.c:189, size 328

In newer versions of Brew MP ( and above ), log messages may also include the home directory of the module that caused the leak. For example:

*AEEModule.c 00266 Warning -- memory leak,freeing, 0xABCD1010, .\myapp.c:189,
            fs:/mod/myapp, size 328

Any memory leak detected by Brew MP is freed by Brew MP. However, it is still critical to correct any memory leak caused by the application.

Note: Memory leaks from services running in the kernel, or more specifically, memory leaks from code that does not run in the Brew context (for example, service classes) are not detectable by Brew MP.