Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Memory leak messages

When a module is unloaded, Brew MP frees any memory in the module context that was not released by the application (this is considered a leak). It is possible for a module to close, but not be removed from memory. Information on memory leaks is printed through the simulator message window, the Brew MP logger, or the Qualcomm eXtensible Diagnostic Monitory (QXDM) log. QXDM is an AMSS diagnostic tool that includes the ability to capture log files.

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.

Memory leaks in system context or leaks in modules that are always running can exhaust all available memory. Memory leaks often cause memory fragmentation and accelerate a system crash.

When a memory leak is detected, Brew MP generates a memory leak trace message. The messages can be seen with the Brew MP Logger, QXDM, or the Simulator Log window.

4/7/2011 8:58:34 PM AEEModule.c:266 - Warning -- memory leak, freeing,
   0x6755760, .\hello.c:196, fs:/usermods/hello, size 100
Where:
  • 0x6755760 - is the address of the leaked memory allocation.
  • \hello.c:196 - is the file name and line number of the allocation.
  • fs:/usermods/hello - is the module that leaked the memory.
  • size 100 - is the size in bytes.

The leaked memory allocation is returned to the heap.

The Heap Analyzer can be used to debug memory leaks and fragmentation problems.

Getting leak notifications

Applications can register to receive notifications of leaks. To receive the notification, the application must register for the NMASK_SHELL_SYS_ERROR notification.

When a leak is detected, the OEMNTF_SYS_ERROR notification is sent. The notification data, AEESysError, contains the error information.

se.nType = SYSERR_MEMFREE;
se.nErr  = EALLOCATED;
se.cls   = class id of module.

Enabling heap debugging on the device

To enable heap debugging on the device so that the filename and line number can be displayed instead of NONAME, in the source file before including AEEStdLib.h, add the following:

  • For allocations through macros (for example, MALLOC, REALLOC), define AEE_DBG_HEAP to be 1.
  • For allocations through the IEnv and IRealloc interfaces, define _HEAP_DEBUG to be 1.

For example:

#define AEE_DBG_HEAP1
#define _HEAP_DEBUG 1
#include"AEEStdLib.h”

With heap debugging enabled, memory leaks are reported as follows:

AEEModule.c00266Warning --memory leak,freeing,0xABCD1010, .\myapp.c:189, 
      size328AEEModule.

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

AEEModule.c00266Warning --memory leak,freeing,0xABCD1010, .\myapp.c:189,fs:/mod/myapp,
      size328

Interface (object) leaks

Leaked objects are not directly reported, but indirectly, by analyzing memory leak reports it is possible to identify leaked objects.

A sample set of leak notifications when an IWindowMgr object is not released before an application is removed from memory:

4/7/2011 8:54:16 PM AEEModule.c:266 - Warning -- memory leak, freeing,
 0x7370680, ModEnv, fs:/usermods/hello, size 108
4/7/2011 8:54:16 PM AEEModule.c:266 - Warning -- memory leak, freeing,
 0x738E220, ZTARemoteObject, fs:/usermods/hello, size 28
4/7/2011 8:54:16 PM AEEModule.c:266 - Warning -- memory leak, freeing,
 0x738E260, IWindowMgrApp1Stub, fs:/usermods/hello, size 28
4/7/2011 8:54:17 PM AEEModule.c:266 - Warning -- memory leak, freeing,
 0x738E4E0, WindowMgr1, fs:/usermods/hello, size 40
4/7/2011 8:54:17 PM AEEModule.c:266 - Warning -- memory leak, freeing,
 0x738E5E0, NONAME, fs:/usermods/hello, size 24
4/7/2011 8:54:17 PM AEEModule.c:266 - Warning -- memory leak, freeing,
 0x738E6A0, ZTARemoteObject, fs:/usermods/hello, size 28
4/7/2011 8:54:17 PM AEEModule.c:266 - Warning -- memory leak, freeing,
 0x738E6E0, ZTARemoteObject, fs:/usermods/hello, size 28
4/7/2011 8:54:17 PM AEEModule.c:266 - Warning -- memory leak, freeing,
 0x738EE00, src/libmod.c:118, fs:/usermods/hello, size 52
4/7/2011 8:54:17 PM AEEModule.c:266 - Warning -- memory leak, freeing,
 0x738EE60, NONAME, fs:/usermods/hello, size 44
4/7/2011 8:54:17 PM AEEModule.c:266 - Warning -- memory leak, freeing,
 0x7393760, StubIQI, fs:/usermods/hello, size 16
4/7/2011 8:54:17 PM AEEModule.c:266 - Warning -- memory leak, freeing,
 0x73937B0, StubIMemMap, fs:/usermods/hello, size 16
4/7/2011 8:54:17 PM AEEModule.c:266 - Warning -- memory leak, freeing,
 0x740B5E0, NONAME, fs:/usermods/hello, size 102

Notice that each leak notification points to files not in the user application, or have NONAME where the source file and line number should be.

For more information, see Resolving interface leaks.