即使在弹出qInt队列中的所有元素之后,以下代码仍未释放3000个元素的内存消耗。是什么原因 ?std ::队列内存消耗导致内存泄漏 - C++?
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
您是否使用任务管理器检查内存消耗? – Borgleader
@Borgleader当然是 – Carthi
你永远不知道,你可能会推3000多个项目进入该队列。如果您希望释放堆内存的最佳机会为即将到来的假设做好准备,请将其与本地空闲自动交换。 – WhozCraig