Memory management:when rust return memory to OS?

I have done a test: use hashmap insert some string, and use cmd"top -pid" to show the progressInfo,the memory footprint slowly gets higher, but when I remove,the memory footprint never change even the hashmap have none data。
so,why memory footprint unchanged?when rust return memory to OS?
pls help me!

This StackOverflow answer is written for C++ but does a really good job explaining what's happening here. I'd recommend giving it a read:


The HashMap type will not automatically decrease the size of the allocation, but you can tell it to do so with shrink_to_fit. Additionally the memory is freed when it goes out of scope.


thank u!!I have see this answer, it is really helpful!

yes, i know that, it will free, but not return to os, just in rust virtual memory。
thanks for your kindness ..^ _ ^..

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.