progschj / ThreadPool

A simple C++11 Thread Pool implementation
zlib License
7.64k stars 2.21k forks source link

queue<packaged_task> has memory leaks? #65

Closed regomne closed 5 years ago

regomne commented 5 years ago

When I enqueue some task:

        for (int i = 0; i < 10000; i++)
        {
            pool.enqueue_task([i] {
                cout << i << endl;
            });
        }

After all the task ENDED:

snipaste_2018-12-11_11-35-45

The std::packaged_task don't seem to be released, and they will be released after ThreadPool destructed. The same to queue.

wilx commented 5 years ago

The queue keeps the storage but the tasks themselves get destroyed after they are done.

regomne commented 5 years ago

Thanks, I replaced queue with deque and use its shrink_to_fit to reduce memory .