https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123582
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Thomas Schwinge from comment #0)
> 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?
No, in general that has never been a valid assumption.
For std::map, std::set, std::list, and std::forward_list, it happens to be true
in our implementation (and probably true in libc++ and MSVC, except for the
dynamically-allocated sentinel node that MSVC's std::list requires).
But for std::vector and std::string, assigning a new sequence of zero elements
will not reduce the allocated capacity. You need to call shrink_to_fit() to do
that.
For std::deque and unordered containers, it will free the nodes but not the
array of pointers to nodes.
For std::deque you can call shrink_to_fit() to copy the elements to a new deque
(which will only have as much capacity as required for those elements) and
deallocate the original one.
For unordered containers you can use c.rehash(c.bucket_count()). You can also
adjust the load factor, if you want to increase or decrease the number of
buckets used.
I don't think there's a bug here though.