Unexpected memory leak in multithread program
问题 I'm working on a program using a large number of threads, each thread allocating in heap a few megabytes of memory. When these threads end, a large part of the RAM is kept by the program. Here is an example of code, allocating and freeing 1 MB in 500 threads, which shows this problem: #include <future> #include <iostream> #include <vector> // filling a 1 MB array with 0 void task() { const size_t S = 1000000; int * tab = new int[S]; std::fill(tab, tab + S, 0); delete[] tab; } int main() { std