From daee97fb6b36b04b968456ef724166491681d583 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Fri, 31 Aug 2018 13:05:32 +1000 Subject: [PATCH] Reduce memory usage on ServiceContainer destruction The closures in ServiceContainer::$serviceInstantiators are circular references which prevent destruction of the object. So, delete these when destroy() is called. Also delete the service instances for good measure. Change-Id: Ic8487cb533a09a8fcc69eba4f5d1bbb71558ae08 --- includes/services/ServiceContainer.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/includes/services/ServiceContainer.php b/includes/services/ServiceContainer.php index 30f82955c5..d934d270e4 100644 --- a/includes/services/ServiceContainer.php +++ b/includes/services/ServiceContainer.php @@ -100,6 +100,12 @@ class ServiceContainer implements DestructibleService { } } + // Break circular references due to the $this reference in closures, by + // erasing the instantiator array. This allows the ServiceContainer to + // be deleted when it goes out of scope. + $this->serviceInstantiators = []; + // Also remove the services themselves, to avoid confusion. + $this->services = []; $this->destroyed = true; } -- 2.20.1