【发布时间】:2015-06-14 06:23:16
【问题描述】:
#include <iostream>
#include <string>
#include <deque>
#include <vector>
#include <unistd.h>
using namespace std;
struct Node
{
string str;
vector<string> vec;
Node(){};
~Node(){};
};
int main ()
{
deque<Node> deq;
for(int i = 0; i < 100; ++i)
{
Node tmp;
tmp.vec.resize(100000);
deq.push_back(tmp);
}
while(!deq.empty())
{
deq.pop_front();
}
{
deque<Node>().swap(deq);
}
cout<<"releas\n";
sleep(80000000);
return 0;
}
通过top,我发现我的程序内存大约是61M,为什么?如果Node 中有复制构造函数也没关系。我想知道为什么,而不是如何使其正确。
gcc (GCC) 4.9.1, centos
【问题讨论】:
-
删除 C++ 对象只是使内存可用于将来的分配,它不会将其返回给操作系统。
-
是什么让你认为它不应该是 61mb?
-
@CaptainObvlious 他的问题是为什么在他执行将它们全部从双端队列中弹出的循环之后它没有下降。