diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index ff14770..fb7ae43 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -867,17 +867,17 @@ protected function initializeContainer() { $container_definition = $this->getCachedContainerDefinition(); } - // Building the container creates 1000s of objects. Garbage collection of - // these objects is expensive and appears to be causing segmentation faults - // in PHP 5.6. - $disable_gc = gc_enabled(); - if ($disable_gc) { - gc_collect_cycles(); - gc_disable(); - } // If there is no container and no cached container definition, build a new // one from scratch. if (!isset($container) && !isset($container_definition)) { + // Building the container creates 1000s of objects. Garbage collection of + // these objects is expensive and appears to be causing segmentation + // faults in PHP 5.6. + $disable_gc = gc_enabled(); + if ($disable_gc) { + gc_collect_cycles(); + gc_disable(); + } $container = $this->compileContainer(); // Only dump the container if dumping is allowed. This is useful for @@ -887,6 +887,11 @@ protected function initializeContainer() { $dumper = new $this->phpArrayDumperClass($container); $container_definition = $dumper->getArray(); } + // If garbage collection was disabled prior to rebuilding container, + // re-enable it. + if ($disable_gc) { + gc_enable(); + } } // The container was rebuilt successfully. @@ -897,11 +902,6 @@ protected function initializeContainer() { $class = Settings::get('container_base_class', '\Drupal\Core\DependencyInjection\Container'); $container = new $class($container_definition); } - // If garbage collection was disabled prior to rebuilding container, enable - // it. - if ($disable_gc) { - gc_enable(); - } $this->attachSynthetic($container);