Memory allocation question

I created a vector and I filled with N million element. If I add new element, and I reach the capacity of vector, it will automatic reallocate vector capacity with double size. It's very efficient.

But I tuncate this vector near zero (or zero). Can I shrink the allocated memory?

Yes with Vec in std::vec - Rust It will deallocate or realloc