Opened 7 years ago
Closed 7 years ago
#11419 closed Bugs (wontfix)
Unexpected memory usage with unorderd_map
Reported by: | Owned by: | Daniel James | |
---|---|---|---|
Milestone: | To Be Determined | Component: | unordered |
Version: | Boost Release Branch | Severity: | Optimization |
Keywords: | Cc: |
Description
Unordered map does NO rehash when shrinking (erasing specific elements). When having multiple maps (or even one map) the memory usage become insanely high (arbitrary) and consequently the program lags because of insane cache usage
This is not a memory leak, but a undocumented (and unwanted) behaviour. There are 3 possible ( I figured out ) fixes:
- make rehashing when there are too few elements
- fix documentation to clearly state users must rehash
- add a method with the exact purpose of reducing memory usage
I uploaded the code to reproduce the bug (bug present both in C++11/14 and in boost) here:
*ttps://github.com/Darelbi/PublicProfileTests/blob/master/BoostMemoryUsage/UnorderedMap.cpp
(beware! running the above code literally freeze also the operative system due to huge bandiwth usage). Fixing that problem as soon as possible could automatically increase performance in a lot of clients code, and that would reduce drastically memory usage (wich seems the problem with many applications, it is suprising no one profiled that!)
Change History (2)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
This is as specified in the standard. If you have an issue with it, you'll need to take it up with the standard committee.
not only, calling "clear" does not reset memory! The only way actually to effectively make sure unordered map free all used memory is to make sure it goes out of scope (or wrap it with a smart pointer to be able to delete it).
calling "clear();" followed by "rehash(0)"; seems to reduce memory usage to few bytes (but still some memory is allocated!)