Closed sundy-li closed 2 years ago
This is expected behavior.
You are allocating a structure which contains a std::vec::Vec<T>
in it and implicitly drops the Vec<T>
when the structure is dropped. Bump
does not run Drop
implementations of things allocated inside it (as documented in the readme, crate-level docs, and docs for Bump
) and it is std::vec::Vec<T>
's drop that deallocates the underlying heap storage. Therefore the heap storage is never reclaimed.
You can use bumpalo::collections::Vec<T>
instead, which will allocate space for its entries from a Bump
and which will run each elements' drop implementation.
Thanks, what about other collections if I need? eg: HashSet, HashMap
The hashbrown
crate has hash sets and maps that can be parameterized by an allocator, and you can enable the nightly allocator trait implementation in this crate to use Bump
with them.
Codes:
using top to watch the RES memory after running above tests: