Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close connections and clear managers on shutdown #366

Merged
merged 1 commit into from Feb 18, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions DoctrineBundle.php
Expand Up @@ -23,6 +23,7 @@
use Symfony\Component\Console\Application;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\IntrospectableContainerInterface;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\DoctrineValidationPass;
use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterEventListenersAndSubscribersPass;
Expand Down Expand Up @@ -113,6 +114,24 @@ public function shutdown()
spl_autoload_unregister($this->autoloader);
$this->autoloader = null;
}

// Clear all entity managers to clear references to entities for GC
if ($this->container->hasParameter('doctrine.entity_managers')) {
foreach ($this->container->getParameter('doctrine.entity_managers') as $id) {
if (!$this->container instanceof IntrospectableContainerInterface || $this->container->initialized($id)) {
$this->container->get($id)->clear();
}
}
}

// Close all connections to avoid reaching too many connections in the process when booting again later (tests)
if ($this->container->hasParameter('doctrine.connections')) {
foreach ($this->container->getParameter('doctrine.connections') as $id) {
if (!$this->container instanceof IntrospectableContainerInterface || $this->container->initialized($id)) {
$this->container->get($id)->close();
}
}
}
}

/**
Expand Down