std :: queue内存消耗会导致内存泄漏 - C++?

Car*_*thi 4 c++ memory queue stl visual-c++

即使在我弹出qInt队列中的所有元素之后,以下代码也没有释放3000个元素所消耗的内存.是什么原因 ?

std::queue<int> qInt; //Step01: Check the running memory

for (int i=0;i<3000;i++)
{       
    qInt.push(i);
}
//Step02: Check the running memory it should have been increased    

while(!qInt.empty())
{
    qInt.pop();
}
//Step03: Check the running memory expecting Step01 memory but it is still the same of Step02
Run Code Online (Sandbox Code Playgroud)

rer*_*run 7

通过defalut std容器一旦保留它就不会释放内存.std :: queue通常在std :: dequeue类型上实现,它提供了shrink_to_fit.如果你不使用c ++ 11,请使用交换习语.