Should CUDA events and threads always be destroyed?

I read CUDA By Example, and I found that when they introduced events, they triggered cudaEventDestroyfor each event they created.

However, I noticed that some later examples neglected this cleanup function. Are there any undesirable side effects associated with forgetting to destroy the created events and threads (i.e., how is a memory leak when you forget to free allocated memory)?

+5
source share
2 answers

Any resources that the application still holds at the time of exit will be automatically released by the OS / drivers. Thus, if the application creates only a limited number of events, there is no need to release them manually. However, allowing the application to exit without releasing all the resources is bad practice because it is difficult to distinguish between true leaks and leaks "for their intended purpose."

+5
source

You have identified errors in the sample code for the book.

CUDA events are lightweight, but a resource leak is a resource leak. Over time, if you miss them enough, you can no longer create them.

0
source

All Articles