Memory Leak in ISHELL_LoadResData | developer.brewmp.com Memory Leak in ISHELL_LoadResData | developer.brewmp.com

Developer

Memory Leak in ISHELL_LoadResData

Forums:

When a use the code bellow, I always get a memory leak in ISHELL_LoadResData. Am I doing something wrong or ISHELL_LoadResData has a bug??? :confused:

uint32 memory;
void *ptr = NULL;
const char *resource_file = "resource.bar";

IHeap *heap = NULL;
ISHELL_CreateInstance(pMe->pIShell, AEECLSID_HEAP, (void**)&heap);
memory = IHEAP_GetMemStats(heap);

//Memory controlled area-----------------------------------------

ptr = ISHELL_LoadResData (pMe->pIShell, resource_file, 5001, RESTYPE_IMAGE);
if (ptr) ISHELL_FreeResData(pMe->pIShell, ptr);

//Memory controlled area-----------------------------------------

memory = IHEAP_GetMemStats(heap) - memory;
IHEAP_Release(heap);

//memory should be 0 byte... but isn't.
DBGPRINTF(">>> Memory Leak: %i bytes <<<", memory);

Well, I wouldn't rely on IHEAP_GetMemStats, as BREW may postpone releasing particular objects internally, and that's why you see the difference.

Well, I wouldn't rely on IHEAP_GetMemStats, as BREW may postpone releasing particular objects internally, and that's why you see the difference.

Anyway, I had a memory leak problem and when I stripped off ISHELL_LoadResData from my code, the leak stopped. It's awful bad that in the documentation there's nothing about BREW using and not releasing memory during runtime... (if it's the case)

Anyway, I had a memory leak problem and when I stripped off ISHELL_LoadResData from my code, the leak stopped. It's awful bad that in the documentation there's nothing about BREW using and not releasing memory during runtime... (if it's the case)

novaes wrote:Anyway, I had a memory leak problem and when I stripped off ISHELL_LoadResData from my code, the leak stopped. It's awful bad that in the documentation there's nothing about BREW using and not releasing memory during runtime... (if it's the case)
The code you posted is not a legitimate way to detect a memory leak. There is only one heap for all of BREW. IHEAP_GetMemStats() returns the total memory in use, which will go up when you allocate memory, when BREW allocates memory, or when any other app allocates memory.
If a memory leak occurs in the simulator, it will tell you about it when you exit your app. (This is assuming the skin is not configured to use the Windows heap.)

novaes wrote:Anyway, I had a memory leak problem and when I stripped off ISHELL_LoadResData from my code, the leak stopped. It's awful bad that in the documentation there's nothing about BREW using and not releasing memory during runtime... (if it's the case)
The code you posted is not a legitimate way to detect a memory leak. There is only one heap for all of BREW. IHEAP_GetMemStats() returns the total memory in use, which will go up when you allocate memory, when BREW allocates memory, or when any other app allocates memory.
If a memory leak occurs in the simulator, it will tell you about it when you exit your app. (This is assuming the skin is not configured to use the Windows heap.)