martinus / robin-hood-hashing

Fast & memory efficient hashtable based on robin hood hashing for C++11/14/17/20
https://gitter.im/martinus/robin-hood-hashing
MIT License
1.5k stars 142 forks source link

How to completely deallocate a hashmap #108

Closed seven7777777 closed 3 years ago

seven7777777 commented 3 years ago

I have a map type robin_hood::unordered_map<uint64_t, uint64_t>, and I insert more than 200 million kv pair into map, but it just does not release any memory to os when I destroy the map object.

martinus commented 3 years ago

That's a bit tricky because the map tries to keep the memory so it doesn't have to allocate any more, but you can do it like this:

robin_hood::unordered_map<uint64_t, uint64_t>().swap(yourMap);
martinus commented 3 years ago

Edit: wait a minute, do you mean it does not deallocate even when you destroy the map?

martinus commented 3 years ago

closing, cannot reproduce