M
MickeyJerry
Linux 2.4.21-37.EL / gcc version 3.2.3 20030502 (Red Hat Linux
3.2.3-47) / libstdc++.so.5
struct O
{
//vector<int> v;
vector<string> v;
void load()
{
char buf[128];
for (int i = 0; i < 1024 * 1024; i++)
{
sprintf(buf, "%d", i);
//v.push_back(i);
v.push_back(buf);
}
}
};
int main()
{
//1
{
O o;
o.load();
//2
}
//3
}
when using vector<int>, memory usage at //1,//2, //3 :
PID %CPU %MEM VSZ RSS
1 17633 0.1 0.1 2272 688
2 17633 2.2 0.9 6508 5008
3 17633 1.8 0.1 2408 908
when using vector<string> :
PID %CPU %MEM VSZ RSS
1 17670 0.1 0.1 2284 688
2 17670 5.6 5.8 31728 29560
3 17670 4.6 5.0 27628 25460
when o leaves its scope(at //3), the strings in vector<string> are not
freed
(vss & rss are not decreesed as vector<int> does).
it must be the libstdc++ library that keeps this portion memory for
later usage
is there any way to disable this behaviour ?
because it seems like a kind of 'leak' if we have a server program
which should run for a long time and use string frequently.
ps. exporting GLIBCPP_FORCE_NEW or GLIBCXX_FORCE_NEW seems taking no
effect
3.2.3-47) / libstdc++.so.5
struct O
{
//vector<int> v;
vector<string> v;
void load()
{
char buf[128];
for (int i = 0; i < 1024 * 1024; i++)
{
sprintf(buf, "%d", i);
//v.push_back(i);
v.push_back(buf);
}
}
};
int main()
{
//1
{
O o;
o.load();
//2
}
//3
}
when using vector<int>, memory usage at //1,//2, //3 :
PID %CPU %MEM VSZ RSS
1 17633 0.1 0.1 2272 688
2 17633 2.2 0.9 6508 5008
3 17633 1.8 0.1 2408 908
when using vector<string> :
PID %CPU %MEM VSZ RSS
1 17670 0.1 0.1 2284 688
2 17670 5.6 5.8 31728 29560
3 17670 4.6 5.0 27628 25460
when o leaves its scope(at //3), the strings in vector<string> are not
freed
(vss & rss are not decreesed as vector<int> does).
it must be the libstdc++ library that keeps this portion memory for
later usage
is there any way to disable this behaviour ?
because it seems like a kind of 'leak' if we have a server program
which should run for a long time and use string frequently.
ps. exporting GLIBCPP_FORCE_NEW or GLIBCXX_FORCE_NEW seems taking no
effect