Javascript是否删除已删除的DOM元素的事件处理程序? [英] Does Javascript remove event handlers of deleted DOM elements?

查看:128
本文介绍了Javascript是否删除已删除的DOM元素的事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将一些事件附加到某些DOM元素中,然后删除它们 - 还将使用用于其事件处理程序或其他属性的内存?

If I attached a bunch of events to some DOM elements - and then remove them - will the memory used for their event handlers or other attributes still be used?

我问,因为我想知道我是否会使用一堆内存,如果我继续使用AJAX请求中的新元素重新填充一个页面,并将绑定事件绑定到它们 - 只有删除它们,并在新的AJAX结果到来时重复该过程

I ask because I want to know if I will use a bunch of memory if I keep refilling an area of a page with new elements from AJAX requests and binding events to them - only to delete them and repeat the process when a new AJAX result comes in.

推荐答案

是的,现代浏览器(最终)释放DOM节点中的事件处理程序使用的内存。但是,旧版本的Internet Explorer没有,所以在从DOM移除节点之前,先删除事件监听器是一贯的。

Yes, modern browsers (eventually) release the memory used by event handlers in DOM nodes. However, old versions of Internet Explorer don't, so it's always good practice to remove event listeners before removing the nodes from the DOM.

这是一个很好的文章,发生了什么: http://msdn.microsoft。 com / en-us / library / bb250448(v = vs85).aspx

This is a good article for understanding what's going on: http://msdn.microsoft.com/en-us/library/bb250448(v=vs.85).aspx

这篇关于Javascript是否删除已删除的DOM元素的事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆