diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index 3f53d04..fb7ae43 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -870,6 +870,14 @@ protected function initializeContainer() {
     // 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
@@ -879,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.
diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh
index 09a7aad..15a59eb 100755
--- a/core/scripts/run-tests.sh
+++ b/core/scripts/run-tests.sh
@@ -147,6 +147,8 @@
 drupal_set_time_limit(0);
 simpletest_script_reporter_init();
 
+$args['repeat'] = 60;
+$test_list = ['\Drupal\FunctionalTests\ContainerRebuildTest'];
 $tests_to_run = array();
 for ($i = 0; $i < $args['repeat']; $i++) {
   $tests_to_run = array_merge($tests_to_run, $test_list);
diff --git a/core/tests/Drupal/FunctionalTests/ContainerRebuildTest.php b/core/tests/Drupal/FunctionalTests/ContainerRebuildTest.php
new file mode 100644
index 0000000..52c4cea
--- /dev/null
+++ b/core/tests/Drupal/FunctionalTests/ContainerRebuildTest.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Drupal\FunctionalTests;
+
+use Drupal\Component\DependencyInjection\Container;
+use Drupal\Tests\BrowserTestBase;
+
+/**
+ * Explicit test for BrowserTestBase::getTestMethodCaller().
+ *
+ * @group browsertestbase
+ */
+class ContainerRebuildTest extends BrowserTestBase {
+
+  protected $profile = 'standard';
+
+  /**
+   * Rebuild the container a few times
+   */
+  public function testRebuildContainer() {
+    $kernel = \Drupal::service('kernel');
+    for ($i = 1; $i <= 10; $i++) {
+      $kernel->invalidateContainer();
+      $container = $kernel->rebuildContainer();
+      $this->assertInstanceOf(Container::class, $container);
+      $this->drupalGet('<front>');
+    }
+  }
+
+}
