From 562911dbff6e445af31b689b6ca2aa7426a0187a Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 15 Apr 2018 01:27:07 +0200 Subject: [PATCH] Lazy class: Destroy the wrapped T object when the Lazy instance gets destroyed. --- include/MUtils/Lazy.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/MUtils/Lazy.h b/include/MUtils/Lazy.h index 3f6eb10..e5fb12d 100644 --- a/include/MUtils/Lazy.h +++ b/include/MUtils/Lazy.h @@ -69,6 +69,14 @@ namespace MUtils return *m_value; } + ~Lazy(void) + { + if(T *const value = m_value.fetchAndStoreOrdered(NULL)) + { + delete value; + } + } + private: QAtomicPointer m_value; const std::function m_initializer;