changeset 967:1b80b9df0d32

Plugged a JavaScript memory leak
author Adam Chlipala <adamc@hcoop.net>
date Sat, 19 Sep 2009 15:59:22 -0400
parents c2fe1dbaceb9
children b8048f6e25ef
files lib/js/urweb.js
diffstat 1 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/lib/js/urweb.js	Sat Sep 19 14:56:03 2009 -0400
+++ b/lib/js/urweb.js	Sat Sep 19 15:59:22 2009 -0400
@@ -189,6 +189,7 @@
 }
 function sv(s, v) {
   s.data = v;
+
   for (var ls = s.dyns; ls; ls = ls.next)
     if (!ls.dead)
       populate(ls.data);
@@ -262,6 +263,14 @@
 
 // Dynamic tree entry points
 
+function killScript(scr) {
+  scr.dead = true;
+  for (var ls = scr.sources; ls; ls = ls.next)
+    ls.data.dyns = remove(scr, ls.data.dyns);
+  for (var ls = scr.closures; ls; ls = ls.next)
+    freeClosure(ls.data);
+}
+
 function dyn(pnode, s) {
   var x = document.createElement("script");
   x.dead = false;
@@ -278,16 +287,11 @@
     var next;
     for (var child = firstChild; child && child != x; child = next) {
       next = child.nextSibling;
+      killScript(child);
       if (child.getElementsByTagName) {
         var arr = child.getElementsByTagName("script");
-        for (var i = 0; i < arr.length; ++i) {
-          var span = arr[i];
-          span.dead = true;
-          for (var ls = span.sources; ls; ls = ls.next)
-            ls.data.dyns = remove(span, ls.data.dyns);
-          for (var ls = span.closures; ls; ls = ls.next)
-            freeClosure(ls.data);
-        }
+        for (var i = 0; i < arr.length; ++i)
+          killScript(arr[i]);
       }
 
       if (child.parentNode)