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.
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.
It is just that the Go core team have their own philosophy.
> However, let’s say we want to store one hour of data. Meanwhile, our company has decided to have a big promotion for Black Friday: in one hour, we may have millions of customers connected to our system. But a few days after Black Friday, our map will contain the same number of buckets as during the peak time. This explains why we can experience high memory consumption that doesn’t significantly decrease in such a scenario.
> What are the solutions if we don’t want to manually restart our service to clean the amount of memory consumed by the map?
I don’t see that as a strong argument for making the implementation of maps more complex by adding some auto- shrinking. If your process survived Black Friday with a map full of items, why would it run out of memory after it with a map that’s mostly empty but didn’t return bookkeeping memory to the heap? Your process likely will keep running. There may be a slight performance drop because cache lookups become more likely to lead to cache misses, but otherwise, the typical system won’t care much about the use of virtual memory space.
Why is it that every shortcoming of Go is spun by its advocates into something that is actually a good thing?
Edit: rephrasing your comment “why is it that every time I say something misleading about go people disagree with me?”
https://learn.microsoft.com/en-us/dotnet/api/system.collecti...