How do I force my std::map to deallocate memory used?
Posted
by monkeyking
on Stack Overflow
See other posts from Stack Overflow
or by monkeyking
Published on 2010-04-13T11:17:47Z
Indexed on
2010/04/13
11:23 UTC
Read the original article
Hit count: 249
I'm using a std::map, and I can't seem to free the memory back to the OS. It looks like,
int main(){
aMap m;
while(keepGoing){
while(fillUpMap){
//populate m
}
doWhatIwantWithMap(m);
m.clear();
//flush some buffered values into map for next iteration
flushIntoMap(m);
}
}
Each (fillUpmap) allocates around 1gig, so I'm very much interested in getting this back to my system before it eats up all my memory.
Ive experienced the same with std::vector, but there I could force it to free by doing a swap with an empty std::vector. This doesn't work with map.
When I use valgrind it says that all memory is freed, so its not a problem with a leak, since everything is cleared up nicely after a run.
© Stack Overflow or respective owner