@@ -1051,6 +1051,26 @@ ur_result_t ur_event_handle_t_::getOrCreateHostVisibleEvent(
10511051 return UR_RESULT_SUCCESS;
10521052}
10531053
1054+ /* *
1055+ * @brief Destructor for the ur_event_handle_t_ class.
1056+ *
1057+ * This destructor is responsible for cleaning up the event handle when the
1058+ * object is destroyed. It checks if the event (`ZeEvent`) is valid and if the
1059+ * event has been completed (`Completed`). If both conditions are met, it
1060+ * further checks if the associated queue (`UrQueue`) is valid and if it is not
1061+ * set to discard events. If all conditions are satisfied, it calls
1062+ * `zeEventDestroy` to destroy the event.
1063+ *
1064+ * This ensures that resources are properly released and avoids potential memory
1065+ * leaks or resource mismanagement.
1066+ */
1067+ ur_event_handle_t_::~ur_event_handle_t_ () {
1068+ if (this ->ZeEvent && this ->Completed ) {
1069+ if (this ->UrQueue && !this ->UrQueue ->isDiscardEvents ())
1070+ ZE_CALL_NOCHECK (zeEventDestroy, (this ->ZeEvent ));
1071+ }
1072+ }
1073+
10541074ur_result_t urEventReleaseInternal (ur_event_handle_t Event) {
10551075 if (!Event->RefCount .decrementAndTest ())
10561076 return UR_RESULT_SUCCESS;
@@ -1073,6 +1093,7 @@ ur_result_t urEventReleaseInternal(ur_event_handle_t Event) {
10731093 if (Event->OwnNativeHandle ) {
10741094 if (DisableEventsCaching) {
10751095 auto ZeResult = ZE_CALL_NOCHECK (zeEventDestroy, (Event->ZeEvent ));
1096+ Event->ZeEvent = nullptr ;
10761097 // Gracefully handle the case that L0 was already unloaded.
10771098 if (ZeResult && ZeResult != ZE_RESULT_ERROR_UNINITIALIZED)
10781099 return ze2urResult (ZeResult);
0 commit comments