From 2ff884328767c4e6a01cba4d0466e67125e86092 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Tue, 19 Apr 2022 10:23:44 -0700 Subject: [PATCH] Fix memory leak occurs every one second --- src/lib/support/Pool.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib/support/Pool.h b/src/lib/support/Pool.h index b311d4de73efd8..399c357f7bdaf7 100644 --- a/src/lib/support/Pool.h +++ b/src/lib/support/Pool.h @@ -343,9 +343,17 @@ class HeapObjectPool : public internal::Statistics, public internal::PoolCommon< internal::HeapObjectListNode * node = mObjects.FindNode(object); if (node != nullptr) { - // Note that the node is not removed here; that is deferred until the end of the next pool iteration. node->mObject = nullptr; Platform::Delete(object); + + // Note need to be released immediately if not in the middle of iteration, otherwise cleanup is deferred + // until the end of the next pool iteration. + if (mObjects.mIterationDepth == 0) + { + node->Remove(); + Platform::Delete(node); + } + DecreaseUsage(); } }