https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123582
Bug ID: 123582
Summary: C++ unordered associative container: dynamic memory
management
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: tschwinge at gcc dot gnu.org
CC: waffl3x at gcc dot gnu.org
Target Milestone: ---
Consider constructing an (empty) unordered associative container 'c'
('std::unordered_map', 'std::unordered_multimap', 'std::unordered_multiset',
'std::unordered_set'), and then gradually populating it, which dynamically has
to allocate memory for the hash table as well as the nodes.
I understand that 'clear()' doesn't necessarily have to deallocate all that
memory, but my assumption is that when overwriting such an unordered
associative container 'c' with a pristine instance: 'c = {};', then all memory
of 'c' should get deallocated? I have not yet properly debugged this, but it
appears as if the latter also only deallocates memory for the nodes, but not
for the hash table? Is this intentional? Is there a way to completely clear
out an unordered associative container (other than destructing it)?
Is my assumption generally valid for C++ container objects, that when
overwriting 'c' with an empty instance: `c = {};`, then all memory of 'c'
should get deallocated?
I'm observing this issue in a code offloading setting (test cases soon to
appear), using OpenMP Unified Shared Memory.