I’m working just few days with jQuery, so question might be not very interesting.
I have DIV reloaded on button press over ajax. DIV content itself registers click handler for button. So the question is: should I remove handler which loaded content had registered?
I make little experiment and looks like I shouldn’t. But is it really true?
If elements are removed from the DOM and you have no further references to them, the event handlers will eventually be garbage collected as well.
But if you have a reference, like
then even if the element is removed by your update process,
someElementwill still hold a reference to that element. This also means that the event handlers still exist in memory.