bug #25204 [DI] Clear service reference graph (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Clear service reference graph

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes (memory usage)
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Spotted while playing with the container: we keep this graph in memory even it its stale already.
Clearing it also leave circular refs for the php garbage collector, better clean ourselves.

Commits
-------

2744b41 [DI] Clear service reference graph
This commit is contained in:
Nicolas Grekas 2017-11-29 17:40:14 +01:00
commit ad3ddebf90
4 changed files with 14 additions and 0 deletions

View File

@ -159,6 +159,8 @@ class Compiler
}
throw $e;
} finally {
$this->getServiceReferenceGraph()->clear();
}
}
}

View File

@ -75,6 +75,9 @@ class ServiceReferenceGraph
*/
public function clear()
{
foreach ($this->nodes as $node) {
$node->clear();
}
$this->nodes = array();
}

View File

@ -107,4 +107,12 @@ class ServiceReferenceGraphNode
{
return $this->value;
}
/**
* Clears all edges.
*/
public function clear()
{
$this->inEdges = $this->outEdges = array();
}
}

View File

@ -142,6 +142,7 @@ class PhpDumper extends Dumper
$currentPath = array($id => $id);
$this->analyzeCircularReferences($node->getOutEdges(), $checkedNodes, $currentPath);
}
$this->container->getCompiler()->getServiceReferenceGraph()->clear();
$this->docStar = $options['debug'] ? '*' : '';