I call the following void function()
function every 40ms and I found that the memory consumption increase steadily. The consumption is not obvious at first but after days, the consumption is huge. Can anyone help to explain what is wrong with this code. Is it a thread problem or std::move
problem that caused the memory leak.
void do_task(const std::vector<int>& tmp)
{
// do some work here
}
void function()
{
std::vector<std::thread> task;
std::vector<int> tmp1, tmp2;
GetTempValue(tmp1);
GetTempValue(tmp2);
task.push_back(std::thread(do_task, std::move(tmp1)));
task.push_back(std::thread(do_task, std::move(tmp2)));
tmp1.clear();
tmp2.clear();
UpdateTempValue(tmp1);
UpdateTempValue(tmp2);
task.push_back(std::thread(do_task, std::move(tmp1)));
task.push_back(std::thread(do_task, std::move(tmp2)));
tmp1.clear();
tmp2.clear();
for(int i=0; i<task.size(); i++)
{
task[i].join();
}
}