Debugging Dynamic Memory Usage Errors Using HP WDB (766161-001, March 2014)
When the memory consumed by the application exceeds the resource limits set by the kernel, the
application fails with out-of-memory errors.
WDB enables you to detect out-of-memory conditions through runtime memory checking. It also
enables you to simulate out-of-memory conditions in an application to understand application
behavior under such conditions.
For information on how you can use WDB to simulate and detect out-of-memory conditions in an
application, see “Error Injection ” (page 23)
Types of Memory Leaks
Following are the types of memory leaks:
• Physical Leaks
A physical leak is a definite memory leak that occurs when an application loses all handles,
or all pointers to the allocated memory. If a valid pointer to a memory block is absent, the
elusive block of memory cannot be accessed or freed.
The handles to a memory block are typically lost under the following conditions:
◦ When an application overwrites a pointer that addresses a block of memory with another
address or data
◦ When a pointer variable goes out of scope
◦ When you free a structure or an array that has pointers which are not freed
When all handles to a block of memory are lost, it causes the block to be leaked. Example 23
(page 86), Example 24 (page 87), and Example 25 (page 88) illustrate how WDB detects
memory leaks.
• Logical Leaks
A logical leak occurs when an application fails to optimally utilize the allocated memory. In
this case the allocated block of memory can still be accessed through a pointer variable in
the application.
The typical causes for logical leaks are listed below:
◦ Leaks caused by premature allocation of memory
The application allocates the memory much ahead of the actual use of the allocated
memory.
◦ Leaks caused by delayed de-allocation
The application delays the freeing the allocated block beyond the actual use of the
allocated memory.
◦ Leaks caused by failure to utilize allocated memory
The application allocates memory, but fails to use the allocated memory.
NOTE: WDB supports the debugging of physical memory leaks only. It does not detect
logical memory leaks.
Access Errors
Memory access errors can occur under the following conditions:
• When reading uninitialized local, or heap data
• When reading or writing to nonexistent, unallocated, or unmapped memory
8