diff options
author | Asmir Mustafic <[email protected]> | 2020-07-03 09:27:49 +0200 |
---|---|---|
committer | Asmir Mustafic <[email protected]> | 2020-07-03 09:27:49 +0200 |
commit | d88e167d9cc494a9f5c929f88325a9cbdfbb65d5 (patch) | |
tree | 248efcdf90a6af85fe05b2c595e5045cdf52772f /src | |
parent | 6c5dea561d99641f66caed6a6d3b8827a8052205 (diff) |
mitigate cyclic reference between output rules and the traverser objects
Diffstat (limited to 'src')
-rw-r--r-- | src/HTML5.php | 5 | ||||
-rw-r--r-- | src/HTML5/Serializer/OutputRules.php | 7 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/HTML5.php b/src/HTML5.php index 94faa1e..c857145 100644 --- a/src/HTML5.php +++ b/src/HTML5.php @@ -212,7 +212,10 @@ class HTML5 $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); } diff --git a/src/HTML5/Serializer/OutputRules.php b/src/HTML5/Serializer/OutputRules.php index 1c4e892..ec467f2 100644 --- a/src/HTML5/Serializer/OutputRules.php +++ b/src/HTML5/Serializer/OutputRules.php @@ -182,6 +182,13 @@ class OutputRules implements RulesInterface return $this; } + public function unsetTraverser() + { + $this->traverser = null; + + return $this; + } + public function document($dom) { $this->doctype(); |