"delete" Node Properties in IE6

I’ve been going over Quirksmode’s addEvent contest lately, in particular John Resig’s entry. The event listener is attached to the element with the following lines:


obj['e'+type+fn] = fn;
obj[type+fn] = function(){obj['e'+type+fn]( window.event );}

This fixes the “this” problem. But a lot of people pointed out that this will leak memory if not removed like so (when the event listener is removed, or when the page is unloaded):


delete obj['e'+type+fn];
delete obj[type+fn];

However, I tried adding the deletes, and I got an error in IE6. On further investigation, it appeared that IE6 won’t let you use the delete operator on an element node. Is there another way to free up this memory? This is the best I can do, but some comments suggested it doesn’t really stop the leaks:


obj['e'+type+fn] = obj[type+fn] = null;

Any suggestions?

That’s pretty much what I figured. Well, not the “lipstick on a pig” part, but the whole, “if you’re not using a browser that has addEventListener, then you’ll just have to put up a worse experience” perspective.

Don’t use IE 6? :stuck_out_tongue:

Unless this is a corporate intranet project I wouldn’t worry about saving memory as long as the rest of the code works. Ultimately this is the sort of thing the browser’s garbage collection should handle. I mean, honestly, IE 6 users deserve the degraded browsing experience their browser gives them. Attempting to fix stuff like this is akin to putting lipstick on a pig.

Heh heh. I applaud you for trying. I remember my fights with IE 6.