From fe2de0465d23ad1b359bb4b94ffe4ad223e2d930 Mon Sep 17 00:00:00 2001 From: Yufeng Wang Date: Tue, 19 Apr 2022 13:16:52 -0700 Subject: [PATCH] Fix memory leak occurs every one second (#17516) * Fix memory leak occurs every one second * Update src/lib/support/Pool.h Co-authored-by: Boris Zbarsky Co-authored-by: Boris Zbarsky --- 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..aa0f2e76e7c425 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); + + // The node needs to be released immediately if we are not in the middle of iteration. + // Otherwise cleanup is deferred until all iteration on this pool completes and it's safe to release nodes. + if (mObjects.mIterationDepth == 0) + { + node->Remove(); + Platform::Delete(node); + } + DecreaseUsage(); } }