If cudaFree() is not used in the end, will the memory being used automatically get free, after the application/kernel function using it exits?
Yes.
When your application terminates (be it gracefully or not), all of its memory is reclaimed back by the OS, regardless of whether it had free
d it or not.
Similarly, the memory allocated on the GPU is managed by its driver, which will release all the resources your application held, cudaFree
d or not.
It is however good practice that every allocation has a matching deallocation, so don't use that as an excuse to not deallocate your memory properly :)
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