comparison lib/js/urweb.js @ 967:1b80b9df0d32

Plugged a JavaScript memory leak
author Adam Chlipala <adamc@hcoop.net>
date Sat, 19 Sep 2009 15:59:22 -0400
parents 8c37699de273
children 001edfbe2561
comparison
equal deleted inserted replaced
966:c2fe1dbaceb9 967:1b80b9df0d32
187 function sc(v) { 187 function sc(v) {
188 return {data : v, dyns : null}; 188 return {data : v, dyns : null};
189 } 189 }
190 function sv(s, v) { 190 function sv(s, v) {
191 s.data = v; 191 s.data = v;
192
192 for (var ls = s.dyns; ls; ls = ls.next) 193 for (var ls = s.dyns; ls; ls = ls.next)
193 if (!ls.dead) 194 if (!ls.dead)
194 populate(ls.data); 195 populate(ls.data);
195 } 196 }
196 function sg(s) { 197 function sg(s) {
260 } 261 }
261 262
262 263
263 // Dynamic tree entry points 264 // Dynamic tree entry points
264 265
266 function killScript(scr) {
267 scr.dead = true;
268 for (var ls = scr.sources; ls; ls = ls.next)
269 ls.data.dyns = remove(scr, ls.data.dyns);
270 for (var ls = scr.closures; ls; ls = ls.next)
271 freeClosure(ls.data);
272 }
273
265 function dyn(pnode, s) { 274 function dyn(pnode, s) {
266 var x = document.createElement("script"); 275 var x = document.createElement("script");
267 x.dead = false; 276 x.dead = false;
268 x.signal = s; 277 x.signal = s;
269 x.sources = null; 278 x.sources = null;
276 freeClosure(ls.data); 285 freeClosure(ls.data);
277 286
278 var next; 287 var next;
279 for (var child = firstChild; child && child != x; child = next) { 288 for (var child = firstChild; child && child != x; child = next) {
280 next = child.nextSibling; 289 next = child.nextSibling;
290 killScript(child);
281 if (child.getElementsByTagName) { 291 if (child.getElementsByTagName) {
282 var arr = child.getElementsByTagName("script"); 292 var arr = child.getElementsByTagName("script");
283 for (var i = 0; i < arr.length; ++i) { 293 for (var i = 0; i < arr.length; ++i)
284 var span = arr[i]; 294 killScript(arr[i]);
285 span.dead = true;
286 for (var ls = span.sources; ls; ls = ls.next)
287 ls.data.dyns = remove(span, ls.data.dyns);
288 for (var ls = span.closures; ls; ls = ls.next)
289 freeClosure(ls.data);
290 }
291 } 295 }
292 296
293 if (child.parentNode) 297 if (child.parentNode)
294 child.parentNode.removeChild(child); 298 child.parentNode.removeChild(child);
295 } 299 }