Memory Leak Tool
This short tutorial will show how to use the Memory Leak Tool that is integrated in Symbian OS.
Checking Allocated Resources
The first tool is an observer of memory resource usage. It can only be used on the WINS emulator with a debug build. It is invoked by three different CTRL+ALT+SHIFT+Key sequences :
| Key sequence | Function | |
| CTRL+ALT+SHIFT+A | Display the number of allocated heap cell | |
| CTRL+ALT+SHIFT+B | Display the number of allocated file server resources | |
| CTRL+ALT+SHIFT+C | Display the number of allocated window server resources |
Heap Checking Macros
This second tool allows to check memory allocation in specific part of your code. But you will need to add calls to specific macros in your code:
| Macro | Function | |
|---|---|---|
| __UHEAP_MARK | This macro marks the beginning of the checking on the user heap | |
| __UHEAP_CHECK(n) | Check that 'n' cells have been allocated (and not released) on the heap since the last __UHEAP_MARK macro | |
| __UHEAP_CHECKALL(n) | Check that 'n' cells are allocated on the heap | |
| __UHEAP_MARKEND | This macro marks the end of the checking and detects if some cells have been allocated and not released since __UHEAP_MARK | |
| __UHEAP_MARKENDC(n) | This macro marks the end of the checking and checks that only 'n' cells have been allocated and not released since __UHEAP_MARK |
Here is an usage example:<BR>
...
__UHEAP_MARK; // mark start of checking
CMyClass * a2 = new(ELeave)CMyClass;
CMyClass * a3 = new(ELeave)CMyClass;
...
__UHEAP_CHECK(2); // check that two cells are allocated (a2,a3) since __UHEAP_MARK
__UHEAP_CHECKALL(3); // check that three cells are allocated (a1,a2,a3)
delete(a2);
__UHEAP_MARKEND; // indicate end of checking
// and detects the leak of a3
If you are developing drives or other kernel side modules, you can use __KHEAP_xxx macros for use with the kernel heap.
Alloc Failure Tool
An allocation failure tool is available to stress a little bit your application You can use the following macros:
| Macro | Function |
|---|---|
| __UHEAP_SETFAIL(aType,n) | This macro can be used to specify how the next memory allocation will behave. aType parameter can take the following values: EDeterministic (allocations will fail every n requests), ERandom (allocations will fail randomly, n being a seed for the pseudo-random number generator) or ETrueRandom (allocations will fail randomly) |
| __UHEAP_FAILNEXT(n) | Cause the next allocation to fail |
| __UHEAP_RESET() | Turn off the memory failure |
You can also bring the Allocation Failure Tool window on or off using the CTRL+ALT+SHIFT+P and CTRL+ALT+SHIFT+Q keyboard shortcut.
<BR> <BR>






> Memory Leak Tool
> Memory Leak Tool
Hi Eric, I know its a weired question, : ) But how do u know such things like the shortcuts?!!
anyway, thanks a million for the really gr8 tips and this wonderfull forum
> Memory Leak Tool
For example, S60 1.x SDK help:
Symbian OS v6.1 Edition for C++ » Developer's Guide » Emulator » Emulator Guide » Debug facilities
BR: Wiz