Skip to content

Commit

Permalink
bug #25204 [DI] Clear service reference graph (nicolas-grekas)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nicolas-grekas committed Nov 29, 2017
2 parents 5cb6c93 + 2744b41 commit ad3ddeb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public function compile(ContainerBuilder $container)
}

throw $e;
} finally {
$this->getServiceReferenceGraph()->clear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public function getNodes()
*/
public function clear()
{
foreach ($this->nodes as $node) {
$node->clear();
}
$this->nodes = array();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,12 @@ public function getValue()
{
return $this->value;
}

/**
* Clears all edges.
*/
public function clear()
{
$this->inEdges = $this->outEdges = array();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public function dump(array $options = array())
$currentPath = array($id => $id);
$this->analyzeCircularReferences($node->getOutEdges(), $checkedNodes, $currentPath);
}
$this->container->getCompiler()->getServiceReferenceGraph()->clear();

$this->docStar = $options['debug'] ? '*' : '';

Expand Down

0 comments on commit ad3ddeb

Please sign in to comment.