From: Tim Starling Date: Fri, 31 Aug 2018 03:05:32 +0000 (+1000) Subject: Reduce memory usage on ServiceContainer destruction X-Git-Tag: 1.34.0-rc.0~4209^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=daee97fb6b36b04b968456ef724166491681d583;p=lhc%2Fweb%2Fwiklou.git 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 --- 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; }