It appears the STL maps (and probably other similar templates) never
free allocated memory. Is there some secret "purge" routine to tell
STL to free its free store? Perhaps more to the point, isn't this a
an STL bug?
For example, in the following code I create a map of 500K elements.
At the stub statement at (1), a simple examination of allocated memory
using top shows that about 12MB are allocated. However, stepping
through the remaining lines as the map object is supposedly
deallocated as it's popped off the stack shows that memory is never
freed, but remains on the STL's own free store. (This is not the
case, e.g., for vectors.)
#include <map>
struct intcmp
{
bool operator()(const int i1, const int i2) const
{
return i1 < i2;
}
};
int
foo() {
int i;
map<int,int,intcmp> m;
for (i=0; i<500000; i++)
m[i] = i;
i = 0; <--1
} <--2
int
main() {
foo();
}