Boost C++ Libraries: Ticket #11419: Unexpected memory usage with unorderd_map https://svn.boost.org/trac10/ticket/11419 <p> 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 </p> <p> This is not a memory leak, but a undocumented (and unwanted) behaviour. There are 3 possible ( I figured out ) fixes: </p> <ul><li>make rehashing when there are too few elements </li><li>fix documentation to clearly state users must rehash </li><li>add a method with the exact purpose of reducing memory usage </li></ul><p> I uploaded the code to reproduce the bug (bug present both in C++11/14 and in boost) here: </p> <p> *ttps://github.com/Darelbi/PublicProfileTests/blob/master/BoostMemoryUsage/UnorderedMap.cpp </p> <p> (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!) </p> <p> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11419 Trac 1.4.3 DarioOliveri <oliveridario89@…> Sat, 27 Jun 2015 03:58:12 GMT <link>https://svn.boost.org/trac10/ticket/11419#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11419#comment:1</guid> <description> <p> 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). </p> <p> calling "clear();" followed by "rehash(0)"; seems to reduce memory usage to few bytes (but still some memory is allocated!) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Daniel James</dc:creator> <pubDate>Wed, 13 Jan 2016 23:57:52 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/11419#comment:2 https://svn.boost.org/trac10/ticket/11419#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> 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. </p> Ticket