请参阅下面的代码:
void foo() {
std::ifstream f("data");
string line;
vector<string> r;
while(getline(f, line)) {
r.push_back(line);
}
f.close();
r.resize(0);
}
int main(int argc, char *argv[])
{
foo();
cout << "load done" << endl;
while(1) {;}
return 0;
}
我使用 while(1) 循环来检查htop
工具中的内存使用情况, r 可能使用 5GB RES
,但load done
打印后RES
仍然需要 5GB。有什么问题?