Hi
If I understand correctly jquery tracks all event handlers registrations, and automatically unregisters them upon remove(), empty() and the page ‘unload’ event.
Assuming I register event handlers for custom or system events *only* through the jQuery interface, when would there be any need to explicitly remove event handlers via 'unbind' (aside from within handler itself for single invocation purposes) ?
For example, I assume this would never leak on IE:
$(document).ready(function () {
var _hold = ('#holder');
$("#btnClick").click(function () {
// _hold implicitly available via closure.
// Anonymous handler creates cyclic reference chain:
// _hold references wrapped-set -> which references DOM div -> which references DOM input
alert('clicked');
});
// calling _hold.empty() or _hold.remove() or navigation to a different page breaks the cycle by removing the click handler, no need to call unbind.
});
<div id="holder">
<input id="btnClick" type="button" value="click" />
</div>
Thanks
-Itai