|
|
|
|
|
by tapirl
1325 days ago
|
|
Yes, Go maps never shrink. This is good for most use cases in practice.
Because in practice, map entry deletions happen seldom.
And when map entry deletions are needed, users often hope maps don't shrink, to avoid potential later unnecessary memory allocations and entry moves.
For example, I only do map entry deletions in one of my projects,
In the project, I clear all entries of a map and re-use the map to avoid making new allocations. The current design satisfies my need well. This is more an optimization than a memory leak. To avoid the kind-of memory leak, just make a new map and discard the old one. |
|
maps being magic without a real interface means exposing new API surface is difficult though.