addEventListener memory leaks

前端 未结 2 1326
误落风尘
误落风尘 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:13

    It shouldn't leak. The one browser that's infamous for leaking like hell when an event handler causes a host-object<>JS-object loop is IE (up to version 7), and IE (up to version 8) doesn't support addEventListener.

    Leave this running and see how the browser's memory usage is affected in the long term, if you want to test it in a particular browser.

    (To test it with a reference loop present, move the function click definition up into the replace body.)

提交回复
热议问题