Purge event handlers from a DOM element


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.