diff --git a/src/KingSystem/Utils/SafeDelete.h b/src/KingSystem/Utils/SafeDelete.h index ddaf3fb7..d5bca0b5 100644 --- a/src/KingSystem/Utils/SafeDelete.h +++ b/src/KingSystem/Utils/SafeDelete.h @@ -4,6 +4,9 @@ namespace ksys::util { +/// Deletes an object that was allocatd with a new expression and sets the pointer to nullptr, +/// preventing it from being accidentally reused. +/// It is safe for the pointer to be already nullptr. template inline void safeDelete(T*& pointer) { if (pointer) @@ -11,6 +14,9 @@ inline void safeDelete(T*& pointer) { pointer = nullptr; } +/// Deletes an array that was allocatd with a new[] expression and sets the pointer to nullptr, +/// preventing it from being accidentally reused. +/// It is safe for the pointer to be already nullptr. template inline void safeDeleteArray(T*& pointer) { if (pointer)