summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsmir Mustafic <[email protected]>2020-07-03 09:27:49 +0200
committerAsmir Mustafic <[email protected]>2020-07-03 09:27:49 +0200
commitd88e167d9cc494a9f5c929f88325a9cbdfbb65d5 (patch)
tree248efcdf90a6af85fe05b2c595e5045cdf52772f
parent6c5dea561d99641f66caed6a6d3b8827a8052205 (diff)
mitigate cyclic reference between output rules and the traverser objects
-rw-r--r--src/HTML5.php5
-rw-r--r--src/HTML5/Serializer/OutputRules.php7
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();