Skip to content

Commit

Permalink
Merge pull request #190 from Masterminds/mitigate-cyclic-refs
Browse files Browse the repository at this point in the history
mitigate cyclic reference between output rules and the traverser objects
  • Loading branch information
goetas authored Jul 3, 2020
2 parents 6c5dea5 + d88e167 commit 5376d40
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/HTML5.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ public function save($dom, $file, $options = array())
$trav = new Traverser($dom, $stream, $rules, $options);

$trav->walk();

/*
* release the traverser to avoid cyclic references and allow PHP to free memory without waiting for gc_collect_cycles
*/
$rules->unsetTraverser();
if ($close) {
fclose($stream);
}
Expand Down
7 changes: 7 additions & 0 deletions src/HTML5/Serializer/OutputRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ public function setTraverser(Traverser $traverser)
return $this;
}

public function unsetTraverser()
{
$this->traverser = null;

return $this;
}

public function document($dom)
{
$this->doctype();
Expand Down

0 comments on commit 5376d40

Please sign in to comment.