I allocated some space using thrust device vector as follows:
thrust::device_vector<int> s(10000000000);
How do i free this space explicitly and correctly?
device_vector
deallocates the storage associated when it goes out of scope, just like any standard c++ container.
If you'd like to deallocate any Thrust vector
's storage manually during its lifetime, you can do so using the following recipe:
// empty the vector
vec.clear();
// deallocate any capacity which may currently be associated with vec
vec.shrink_to_fit();
The swap
trick mentioned in Roger Dahl's answer should also work.
clear()
sets the size of the vector to 0, but may not release the associated memory. The standard way to release the memory with STL is to swap the vector with an empty vector. It should work for Thrust as well.
v.clear();
device_vector<T>().swap(v);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With