@@ -1051,6 +1051,26 @@ ur_result_t ur_event_handle_t_::getOrCreateHostVisibleEvent(
1051
1051
return UR_RESULT_SUCCESS;
1052
1052
}
1053
1053
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
+
1054
1074
ur_result_t urEventReleaseInternal (ur_event_handle_t Event) {
1055
1075
if (!Event->RefCount .decrementAndTest ())
1056
1076
return UR_RESULT_SUCCESS;
@@ -1073,6 +1093,7 @@ ur_result_t urEventReleaseInternal(ur_event_handle_t Event) {
1073
1093
if (Event->OwnNativeHandle ) {
1074
1094
if (DisableEventsCaching) {
1075
1095
auto ZeResult = ZE_CALL_NOCHECK (zeEventDestroy, (Event->ZeEvent ));
1096
+ Event->ZeEvent = nullptr ;
1076
1097
// Gracefully handle the case that L0 was already unloaded.
1077
1098
if (ZeResult && ZeResult != ZE_RESULT_ERROR_UNINITIALIZED)
1078
1099
return ze2urResult (ZeResult);
0 commit comments