I think you mean the event handler here, right? If this is the case, then for the purpose of garbage collection it is important to be careful when using functions associated with elements through the "onfoo" attributes. IE has what constitutes a separate garbage collector for the DOM and JavaScript, and they know little about each other.
I believe that itβs enough to make sure that the βonfooβ attributes are set to null when the DOM elements are discarded. Thus, the JavaScript code will break the reference to the JavaScript memory allocated for the handlers, so the DOM garbage collector will not leak. Of course, this applies to any other random attributes that you might have added to the DOM elements too.
Although I do not like to suggest using the JavaScript framework for questions that are not tagged, and in fact I will not really make such a proposal here, but I will say that one of the things that the framework does for you (usually) is try to keep the DOM clean in this situation.
source share