For class types, the theoretical complexity is O(n)
. The destructor is called for each element. Of course, it's up to the implementation to adhere to the observable behavior, so if the destructor is a no-op or the behavior is the same as with just marking the whole chunk as freed, the complexity could be just O(1)
.
For primitive types, the compiler will likely just release the whole chunk of memory at once, thus the complexity O(1)
.