Memory Leak Occurs Due to Unreleased Memory

Symptom

During the long-term stable running of test cases, a memory leak occurs and memory usage keeps increasing. See Figure 1.

Figure 1 Increasing memory consumption

Possible Cause

The possible cause is as follows:

A memory leak occurs because allocated memory is not released. Memory allocation and deallocation must occur in pairs.

Solution

To rectify the fault, perform the following steps:

Check all the memory-related API pairs to ensure the allocated memory is released when the memory is no longer needed. For example, check the API pairs aclrtMalloc/aclrtFree, aclrtMallocHost/aclrtFreeHost, and aclrtCreateStream/aclrtDestroyStream.