From 2a62fe22f81d5ea7dd07679ebff1d62ec30247e7 Mon Sep 17 00:00:00 2001 From: catch <6915-catch@users.noreply.drupalcode.org> Date: Mon, 9 Dec 2024 12:44:36 +0000 Subject: [PATCH] Issue #3492453 by larowlan, catch, longwave, alexpott, godotislate: Memory leak in DrupalKernel when installing modules (cherry picked from commit 57061f4d3926002bf03ceda5491254693bc15818) --- core/lib/Drupal/Core/Installer/InstallerKernel.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/lib/Drupal/Core/Installer/InstallerKernel.php b/core/lib/Drupal/Core/Installer/InstallerKernel.php index 8f4f1c760dee..23f329eff551 100644 --- a/core/lib/Drupal/Core/Installer/InstallerKernel.php +++ b/core/lib/Drupal/Core/Installer/InstallerKernel.php @@ -3,6 +3,7 @@ namespace Drupal\Core\Installer; use Drupal\Core\DrupalKernel; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Extend DrupalKernel to handle force some kernel behaviors. @@ -83,4 +84,17 @@ public static function installationAttempted() { return isset($GLOBALS['install_state']) && empty($GLOBALS['install_state']['installation_finished']); } + /** + * {@inheritdoc} + */ + protected function attachSynthetic(ContainerInterface $container): void { + parent::attachSynthetic($container); + + // Reset any existing container in order to avoid holding on to old object + // references, otherwise memory usage grows exponentially with each rebuild + // when multiple modules are being installed. + // @todo Move this to the parent class after https://www.drupal.org/i/2066993 + $this->container?->reset(); + } + } -- GitLab