Memory leak detection tool

xiaoxiao2021-03-06  38

Text / Peter Jiang (translated from newlc.com) Detection The first tool for the Assigned resource is a listener used by a memory resource. It can only debug on the simulator. You can use shortcuts to call

Key Function Ctrl Alt Shift A Displays the number of allocated stack units Ctrl Alt Shift b Display the number of allocated file server resources Ctrl Alt Shift C Display the number of allocated window server resources quantity stack detection The macro second tool detects the allocation of memory in the code block you specified. Just add these macros to the code part you want to detect:

Macro function __UHEAP_MARK starts detecting the use of the stack __UHEAP_CHECK (N) Detects from the top __uheap_mark whether there is 'n' pile allocated (not released) __UHEAP_CHECKALL (N) detection whether there is 'n' pile allocated __uheap_markend The detection ends and detects that there is no unsealed heap __UHEAP_MARKENDC (N) detection end after __UHEAP_MARK, and detected that there is a simple use example after __UHEAP_MARK

CMYCLASS * A1 = New (Eleave) CMYCLASS; ... __UHEAP_MARK; // Start Detection CMYCLASS * A2 = New (Eleave) CMYCLASS; CMYCLASS * A3 = New (Eleave) CMYCLASS; ... __UHEAP_CHECK (2); // Detection After __UHEAP_MARK, there are 2 stacks that are subtracted (A2, A3) __UHEAP_CHECKALL (3); // Test three stacks have been assigned (A1, A2, A3) Delete (A2); __UHEAP_MARKEND; // End detection, A3 memory disclosure

If you want to design a driver or kernel module, you can use __kheap_xxx macro to detect kernel stacks. Allocation failure tools are used to perform pressure test. You can use the following macro

Macro function __UHEAP_SETFAIL (atype, n) can specify how the next memory is allocated according to the different parameters. The parameter table is as follows: edeeterministic: N requests failed Erandom: Random failed, n is the random number of seed eTruerandom: random failed __uheap_failnext n) Causes the next allocation failure __UHEAP_RESET () avoiding memory failure can also press CTRL ALT SHIFT P and CTRL Alt SHIFT Q in the simulator to use allocation failure tools

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

New Post(0)