Valgrind shows std::vector<> times of alloc is more than free, but no memory leak

后端 未结 3 1436
春和景丽
春和景丽 2021-01-20 22:29

The code is fairly simple:

#include 
int main() {
    std::vector v;
}

Then I build and run it with Valgrind:

3条回答
  •  醉梦人生
    2021-01-20 22:52

    Reported memory still in use by C++ runtime. You don't need to worry about it. Valgrind's FAQ has an entry regarding this problem:

    First of all: relax, it's probably not a bug, but a feature. Many implementations of the C++ standard libraries use their own memory pool allocators. Memory for quite a number of destructed objects is not immediately freed and given back to the OS, but kept in the pool(s) for later re-use.

提交回复
热议问题