What is the Proper Way to Destroy a Map Instance?

前端 未结 7 1553
旧巷少年郎
旧巷少年郎 2020-11-27 13:18

I recently developed an html5 mobile application. The application was a single page where navigation hash change events replaced the entire DOM. One section of the applicati

7条回答
  •  悲哀的现实
    2020-11-27 13:21

    I guess you're talking about addEventListener. When you remove the DOM elements, some browsers leak these events and doesn't remove them. This is why jQuery does several things when removing an element:

    • It removes the events when it can using removeEventListener. That means it's keeping an array with the event listeners it added on this element.
    • It deletes the attributes about events (onclick, onblur, etc) using delete on the DOM element when addEventListener is not available (still, it has an array where it stores the events added).
    • It sets the element to null to avoid IE 6/7/8 memory leaks.
    • It then removes the element.

提交回复
热议问题