Do events handlers on a DOM node get deleted with the node?

后端 未结 5 683
死守一世寂寞
死守一世寂寞 2020-12-01 06:22

(Note: I\'m using jQuery below, but the question is really a general Javascript one.)

Say I\'ve got a div#formsection whose contents are repeatedly upda

5条回答
  •  猫巷女王i
    2020-12-01 06:52

    jQuery goes to great lengths to avoid memory leaks when removing elements from the DOM. As long as you're using jQuery to delete DOM nodes, removal of event handlers and extra data should be handled by jQuery. I would highly recommend reading John Resig's Secrets of a JavaScript Ninja as he goes into great detail on potential leaks in different browsers and how JavaScript libraries like jQuery get around these issues. If you're not using jQuery, you definitely have to worry about leaking memory through orphaned event handlers when deleting DOM nodes.

提交回复
热议问题