Debugging Dynamic Memory Usage Errors Using NonStop Native Inspect White Paper
leaks memory on a continual basis, the virtual memory requirement for the process continues to
increase and this can result in serious consequences for long-running applications and memory
intensive applications.
Memory leaks can also cause fragmentation of the heap. This slows down the allocation,
deallocation, and access of memory blocks and can eventually cause the application to fail with
out-of-memory errors.
When to Suspect a Memory Leak
You must suspect a memory leak in an application if the system runs to it’s allocated limit, runs
slower, or both. Memory leaks in an application increase the memory consumption in an application.
When the memory consumed by the application exceeds the resource limits set by the kernel, the
application fails with out-of-memory errors.
Native Inspect 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.
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 can not 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
9” (page 21), “Example 10” (page 21), and “Example 11” (page 22) illustrate how Native Inspect
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.
Memory-Related Errors 7










