Boost C++ Libraries: Ticket #2908: unordered_map has no destructor! https://svn.boost.org/trac10/ticket/2908 <p> I noticed that the unordered_map has no destructor as one would assume. There should be a destructor that calls clear() so that the content of the map is deleted. (cf. RAII - <a class="ext-link" href="http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization"><span class="icon">​</span>http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization</a>) </p> <p> I ran into a serious memory leak because of that, when using an unordered_map locally and assuming that it clears its content when being destroyed. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2908 Trac 1.4.3 Daniel James Fri, 03 Apr 2009 14:12:13 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2908#comment:1 https://svn.boost.org/trac10/ticket/2908#comment:1 <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">invalid</span> </li> </ul> <p> The memory management is taken care of by an internal implementation class called <code>hash_table_data_equivalent_keys</code> or <code>hash_table_data_unique_keys</code>. You can see the destructor here: </p> <p> <a class="ext-link" href="https://svn.boost.org/trac/boost/browser/trunk/boost/unordered/detail/hash_table_impl.hpp?rev=51995#L380"><span class="icon">​</span>https://svn.boost.org/trac/boost/browser/trunk/boost/unordered/detail/hash_table_impl.hpp?rev=51995#L380</a> </p> <p> The destructor is called <code>BOOST_UNORDERED_TABLE_DATA</code> because I'm using macros to define the two different hash tables with a single implementation. </p> <p> <code>unordered_map</code> and <code>unordered_set</code>'s implicit destructors both call the implementation classes' destructors, so there's no need to define a destructor for those classes. </p> Ticket anonymous Tue, 07 Apr 2009 14:02:06 GMT <link>https://svn.boost.org/trac10/ticket/2908#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2908#comment:2</guid> <description> <p> But somehow the unordered_map was only cleared if and only if I called clear() manually. I can post you some details if you like. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Daniel James</dc:creator> <pubDate>Wed, 08 Apr 2009 09:05:32 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2908#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2908#comment:3</guid> <description> <p> If you send me an example, I'll have a look at it. Let me know which compiler you're using and on which platform. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 27 Apr 2009 16:04:59 GMT</pubDate> <title>version changed https://svn.boost.org/trac10/ticket/2908#comment:4 https://svn.boost.org/trac10/ticket/2908#comment:4 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.38.0</span> → <span class="trac-field-new">Boost 1.37.0</span> </li> </ul> <p> Here is the example (I tried to skip the unnecessary stuff): </p> <p> definitions: </p> <p> typedef boost::tuple&lt;TPoint, TPoint, TPoint&gt; TEdgeIdentifier; typedef std::pair&lt;PTempPlzEdge, unsigned&gt; TCountedEdge; </p> <p> typedef boost::unordered_map&lt;TEdgeIdentifier, TCountedEdge, TEdgeIdentifierHash, TEdgeIdentifierEqual&gt; TEdgeCountMap; </p> <p> method: </p> <hr /> <p> TEdgeCountMap <a class="missing wiki">EdgeCountDifferentMap</a>( 1.5 * List.size() ); for( "it in List" ){ </p> <blockquote> <p> TEdgeCountMap::iterator found = <a class="missing wiki">EdgeCountDifferentMap</a>.find( (*it)-&gt;<a class="missing wiki">GetEdgeIdentifier</a>() ); </p> </blockquote> <blockquote> <p> if( found != <a class="missing wiki">EdgeCountDifferentMap</a>.end() ){ </p> </blockquote> <p> </p> <blockquote> <blockquote> <p> if( "some condition" ){ </p> <blockquote> <p> found-&gt;second.second ++; </p> </blockquote> <p> } </p> </blockquote> <p> }else{ </p> <blockquote> <p> <a class="missing wiki">EdgeCountDifferentMap</a>.insert( std::make_pair( (*it)-&gt;<a class="missing wiki">GetEdgeIdentifier</a>(), std::make_pair( *it , 1 ) ) ); </p> </blockquote> <p> } </p> </blockquote> <p> } </p> <p> for( "it in List" ){ </p> <blockquote> <p> TEdgeCountMap::iterator found = <a class="missing wiki">EdgeCountDifferentMap</a>.find( (*it)-&gt;<a class="missing wiki">GetEdgeIdentifier</a>() ); </p> </blockquote> <blockquote> <p> if( found != <a class="missing wiki">EdgeCountDifferentMap</a>.end() &amp;&amp; found-&gt;second.second &gt; 1 ){ </p> <blockquote> <p> continue; </p> </blockquote> <p> } </p> </blockquote> <blockquote> <p> "do something with *it" </p> </blockquote> <p> } </p> <p> <em> <a class="missing wiki">EdgeCountDifferentMap</a>.clear(); </em> if this is uncommented, I have a huge memory leak although this is the end of the method and <a class="missing wiki">EdgeCountDifferentMap</a> should be destroyed </p> <p> Additionally I noticed (using AQtime 6) that the memory that is allocated within the constructor call "TEdgeCountMap <a class="missing wiki">EdgeCountDifferentMap</a>( 1.5 * List.size() );" is not freed too. </p> <p> I am in the unfortunate situation that I have to use Borland C++ Builder 4. I use boost version 1.37. </p> Ticket anonymous Mon, 25 May 2009 08:15:15 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/2908#comment:5 https://svn.boost.org/trac10/ticket/2908#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">invalid</span> </li> </ul> Ticket Daniel James Mon, 25 May 2009 19:14:12 GMT <link>https://svn.boost.org/trac10/ticket/2908#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2908#comment:6</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/53253" title="Add explicit destructors to the unordered containers. Refs #2908. ...">[53253]</a>) Add explicit destructors to the unordered containers. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2908" title="#2908: Bugs: unordered_map has no destructor! (closed: fixed)">#2908</a>. </p> <p> Isn't really needed but it doesn't hurt. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 27 May 2009 14:45:09 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2908#comment:7 https://svn.boost.org/trac10/ticket/2908#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Well, guess what? That worked! Strange, as I can comprehend your previous reasoning totaly. Seems like the old Borland C++-Compiler has a serious issue there. :( </p> Ticket Daniel James Sat, 30 May 2009 17:34:16 GMT <link>https://svn.boost.org/trac10/ticket/2908#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2908#comment:8</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/53465" title="Merge latest changes for unordered. Improved compatability and a few ...">[53465]</a>) Merge latest changes for unordered. Improved compatability and a few tweaks. </p> <p> Merged revisions 53127,53253,53256,53311,53314,53316-53318 via svnmerge from <a class="ext-link" href="https://svn.boost.org/svn/boost/trunk"><span class="icon">​</span>https://svn.boost.org/svn/boost/trunk</a> </p> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/53127" title="Better configuration for boost.unordered.">r53127</a> | danieljames | 2009-05-20 07:43:38 +0100 (Wed, 20 May 2009) | 1 line </p> </blockquote> <p> </p> <blockquote> <p> Better configuration for boost.unordered. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/53253" title="Add explicit destructors to the unordered containers. Refs #2908. ...">r53253</a> | danieljames | 2009-05-25 20:14:07 +0100 (Mon, 25 May 2009) | 3 lines </p> </blockquote> <p> </p> <blockquote> <p> Add explicit destructors to the unordered containers. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2908" title="#2908: Bugs: unordered_map has no destructor! (closed: fixed)">#2908</a>. </p> </blockquote> <p> </p> <blockquote> <p> Isn't really needed but it doesn't hurt. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/53256" title="Unordered change log for explicit destructors.">r53256</a> | danieljames | 2009-05-25 20:45:23 +0100 (Mon, 25 May 2009) | 1 line </p> </blockquote> <p> </p> <blockquote> <p> Unordered change log for explicit destructors. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/53311" title="Missing changelog entry.">r53311</a> | danieljames | 2009-05-27 18:42:01 +0100 (Wed, 27 May 2009) | 1 line </p> </blockquote> <p> </p> <blockquote> <p> Missing changelog entry. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/53314" title="Use lightweight_test for unordered.">r53314</a> | danieljames | 2009-05-27 18:44:09 +0100 (Wed, 27 May 2009) | 1 line </p> </blockquote> <p> </p> <blockquote> <p> Use lightweight_test for unordered. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/53316" title="Some workarounds for old versions of Borland.">r53316</a> | danieljames | 2009-05-27 19:19:32 +0100 (Wed, 27 May 2009) | 1 line </p> </blockquote> <p> </p> <blockquote> <p> Some workarounds for old versions of Borland. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/53317" title="Fix a change accidentally included in the last commit.">r53317</a> | danieljames | 2009-05-27 19:32:22 +0100 (Wed, 27 May 2009) | 1 line </p> </blockquote> <p> </p> <blockquote> <p> Fix a change accidentally included in the last commit. </p> </blockquote> <p> ........ </p> <blockquote> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/53318" title="Remove an unused function.">r53318</a> | danieljames | 2009-05-27 19:32:38 +0100 (Wed, 27 May 2009) | 1 line </p> </blockquote> <p> </p> <blockquote> <p> Remove an unused function. </p> </blockquote> <p> ........ </p> </description> <category>Ticket</category> </item> </channel> </rss>