Posted By

iTony on 06/25/09


Tagged

javascript ie DOM events bug


Versions (?)

Purge event handlers from a DOM element


 / Published in: PHP
 

URL: http://javascript.crockford.com/memory/leak.html

Memory leakage in IE6/7 if the event handlers are not purged before deleting an element.

  1. Object.protoype.purge = function purge(d) {
  2. var a = d.attributes, i, l, n;
  3. if (a) {
  4. l = a.length;
  5. for (i = 0; i < l; i += 1) {
  6. n = a[i].name;
  7. if (typeof d[n] === 'function') {
  8. d[n] = null;
  9. }
  10. }
  11. }
  12. a = d.childNodes;
  13. if (a) {
  14. l = a.length;
  15. for (i = 0; i < l; i += 1) {
  16. purge(d.childNodes[i]);
  17. }
  18. }
  19. }

Report this snippet  

You need to login to post a comment.