addEventListener memory leaks

前端 未结 2 1321
误落风尘
误落风尘 2021-02-05 22:58

When registering an event via addEventListener on an element, then delete that element without removing the event, and doing so repeatedly, would memory be \"leaked\"?

2条回答
  •  梦谈多话
    2021-02-05 23:21

    You will get memory leak if you delete from DOM, elements that have attached listeners. But this only occurs in IE, Fx and others have advanced GC.

    Often it happens, if you manipulate with DOM elements not via DOM, but like

    el.innerHTML = ...
    

    For example, YUI has custom realization setInnerHTML, to prevent memory leak in this case.

提交回复
热议问题