Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shrink to fit #36

Closed
meox opened this issue Jun 13, 2017 · 4 comments
Closed

shrink to fit #36

meox opened this issue Jun 13, 2017 · 4 comments

Comments

@meox
Copy link

meox commented Jun 13, 2017

Is there somenthing like shrink_to_fit like we have for std::vector?
I tried to use clear and reserve(0) but the memory is not released.

Thanks

@greg7mdp
Copy link
Owner

clear() definitely releases the memory. Depending on the platform you are using (Windows?), you may not notice that the memory has been freed, but it has. For example if, after calling clear(), you create a second hash table with the same elements, the memory usage should not increase.

@meox
Copy link
Author

meox commented Jun 14, 2017

I'm using Linux and Solaris.
The behaviour, respect to memory management, is very similar to std::unordered_map:
seems that the memory is not released to OS after a clear. This is correct in many scenarios but there are some cases that could be usefull to clear and release all the memory back to OS.

@Bu11etmagnet
Copy link

No C++ standard library class or function returns memory "back to the OS". The best C++ classes/methods can do is call delete (which is likely to call free), releasing memory back to the dynamic memory allocator. Whether the dynamic memory allocator releases the memory back to the OS is an implementation detail, not visible from C++.

@meox
Copy link
Author

meox commented Jun 14, 2017

ok thanks for this clarification

@meox meox closed this as completed Jun 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants