需要Unhooking事件处理程序以避免IE中的内存泄漏 [英] Is Unhooking event handlers needed to avoid memory leaks in IE

查看:94
本文介绍了需要Unhooking事件处理程序以避免IE中的内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IE中遇到一些内存泄漏问题。



我一直在阅读,不会在IE中解除事件处理程序,可能会导致内存泄漏。这是真的吗?

当用户离开页面时,我的内存泄漏可能是因为没有分离事件处理程序?

解决方案

Douglas Crockford有一个在JSscript内存泄漏上发表的优秀文章(JScript是IE的实现的JavaScript / ECMAScript)。



它基本上归结为:IE为DOM和JScript分别进行了内存管理(因此也是垃圾收集)。因此,IE无法清理DOM对象和事件处理程序之间的循环引用。



解决此问题的方法是确保始终删除事件在丢弃DOM对象之前,DOM对象的处理程序(或将它们设置为 null )。


I am having some memory leak problems in IE.

I have been reading, that not unhooking event handlers in IE, could cause memory leaks. Is this true?
Could my memory leaks be cause by not detaching event handlers when the user leaves a page?

解决方案

Douglas Crockford has an excellent post on JSscript memory leaks (JScript is IE's implementation of JavaScript/ECMAScript).

It basically comes down to this: IE has separate memory management (and thus garbage collection) for the DOM and for JScript. Because of this, IE has trouble cleaning up the cycling references between DOM objects and event handlers.

The way to work around this is to make sure that you always remove the event handlers from the DOM objects (or set them to null) before you throw away the DOM object.

这篇关于需要Unhooking事件处理程序以避免IE中的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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