Search code examples
c++c++11memory-managementallocator

Does deallocation imply destruction?


More specificly, in C++, does std::allocator_traits<T>::deallocate imply std::allocator_traits<T>::destroy?


Solution

  • No, you have to remember to call destroy() yourself. The allocator doesn't know which objects have been constructed and which have merely been allocated.

    For example, in a vector, objects 0 through v.capacity()-1 have been allocated, but only objects 0 through v.size()-1 have been constructed.