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(); } }