[opw-web] Clean up temporary DOM trees



commit 831500b303073cf1916ec07fce67648ca5f96fba
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Fri Apr 4 12:45:49 2014 -0400

    Clean up temporary DOM trees
    
    After converting to and from an HTML DOM tree, wipe the DOM tree
    since it contains circular references, and we were hitting problems
    with memory usage (even though the garbage collector should have
    been taking care of the problem.)

 classes/class_skin.php |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
---
diff --git a/classes/class_skin.php b/classes/class_skin.php
index ab216f6..4e63311 100644
--- a/classes/class_skin.php
+++ b/classes/class_skin.php
@@ -141,7 +141,13 @@ class skin
             $elt->outertext = '';
         }
 
-        return $html;
+        // The DOM tree is a nest of circular references; to avoid leaking
+        // it and hoping that the garbage collector cleans it up, explicitly
+        // clear it after getting the string result.
+        $result = (string)$html;
+        $html->clear();
+
+        return $result;
     }
 
     // Generates a cache key


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]