Memory leak detection tool

xiaoxiao2021-03-06  41

Memory leak detection tool

Text / peter jiang (translated from newlc.com)

Test allocated resources

The first tool is a listener that is used in memory resources. It can only debug on the simulator. You can use shortcut keys to call

Key Function

Ctrl Alt Shift A Displays the number of assigned stacking units

Ctrl Alt Shift B Displays the number of filed file server resources

Ctrl Alt Shift C Displays the number of allocated window server resources

Pile detection macro

The second tool can detect memory allocation in the code block you specify. Just add these macros to the code section you want to detect:

Macro function

__UHEAP_MARK starts to detect the use of the stack

__UHEAP_CHECK (N) Detection Since the top __uheap_mark is 'n' pile assigned (not yet released)

__UHEAP_CHECKALL (N) Detects whether there is 'n' pile allocated

__UHEAP_MARKEND detection ends, and detects no piles that have not been released after __UHEAP_MARK

__UHEAP_MARKENDC (N) The detection ends, and detects that there is no 'n' unsealed pile after __uheap_mark

This is a simple use example

CMYCLASS * A1 = New (Eleave) CMYCLASS;

...

__UHEAP_MARK; / / Start detection

CMYCLASS * A2 = New (Eleave) CMYCLASS;

CMYCLASS * A3 = New (Eleave) CMYCLASS;

...

__UHEAP_CHECK (2); // Test 2 stack units after __UHEAP_MARK (A2, A3)

__UHEAP_CHECKALL (3); // Test three stacks have been assigned (A1, A2, A3)

Delete (A2);

__UHEAP_MARKEND; // End detection, A3 memory leakage

If you want to design a driver or kernel module, you can use the __kheap_xxx macro to detect the kernel heap.

Assignment failure tool

Used to perform pressure test. You can use the following macro

Macro function

__UHEAP_SETFAIL (atype, n) can specify how the next memory is assigned according to the different parameters.

The parameter table is as follows:

EDeeeeeeterministic: N request failed

Eraandom: Random fail, N is the random number

Etruerandom: Random failure

__UHEAP_FAILNEXT (N) caused next assignment failure

__UHEAP_RESET () Avoid memory failure

You can also press CTRL ALT SHIFT P and CTRL Alt Shift Q to use allocation failure tools in the simulator.

转载请注明原文地址:https://www.9cbs.com/read-77424.html

New Post(0)