使用 IE Javascript 泄漏检测器有困难

发布于 2024-10-02 16:31:28 字数 635 浏览 5 评论 0原文

当使用某些 Javascript 代码模式时,Microsoft 的 IE6 和 IE7 浏览器会出现内存泄漏问题。早在 IE6 早期,我就发现了很多有关泄漏模式的信息。不过,据我所知,其中许多(但不是全部)问题已在 IE7 和 IE6 的服务包中得到修复。我找不到可靠的信息来源来了解 IE6 和 IE7 的修补版本中仍然存在哪些漏洞。

有几种工具可以检测泄漏模式。但我似乎无法按照我想要的方式使用它们!

  • 即使我使用应该泄漏的模式,Microsoft (V2) 内存泄漏检测器也不会在我的代码中发现任何泄漏。 不令人头疼的方法让它假装成 IE6 或 IE7?

  • Drip 和 sIEve 似乎发现了大量“孤儿”品种的泄漏。当然,这些一定是误报——几乎我添加到文档中然后再次删除的每个元素都被列出,并且我不相信我保留了对它们的引用。如果它们是真实的,我怎样才能找到它们在代码中泄漏的位置?这些工具有一个“属性”功能,但没有显示任何内容,使其看起来像是损坏了。同样,我不知道这些泄漏是否与 IE6 或 IE7 有关,或者仅与 IE8(我安装的 IE 版本)相关。

因此,我真的很想知道哪些类型的内存泄漏仍然是 IE6 和 IE7 的修补版本的问题,以及如何使用工具在我的实时代码中有效地找到它们来帮助我。

有什么帮助吗?

Microsoft's IE6 and IE7 browsers suffer from memory leaks when certain Javascript code patterns are used. I've found lots of information on what the leak patterns were, back in early IE6 days. However, I understand that many (but not all) of these were fixed in IE7 and in a service pack for IE6. I can't find a reliable source of information on what leaks still remain in those patched versions of IE6 and IE7.

There are a couple of tools to detect leak patterns. But I can't seem to be able to use them the way I want!

  • Microsoft's (V2) memory leak detector finds no leaks at all in my code even when I use patterns that should leak. This may be because I am running IE8 - is there any non-headachy way to get it to pretend to be IE6 or IE7?

  • Drip and sIEve seem to find tons of leaks of the "orphan" variety. Surely these must be false positives - virtually every element I add to the document then remove again are listed, and I don't believe I keep references to them. And if they are real, how can I find where in my code they are leaking? The tools have a 'properties' feature which shows nothing, making it seem broken. Again, I have no idea whether these leaks are relevant for IE6 or IE7, or just for IE8, which is the version of IE I have installed.

So I'd really like to know what types of memory leaks are still an issue with patched versions of IE6 and IE7, and how to effectively find them in my live code using tools to help me.

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

穿透光 2024-10-09 16:31:28

我认为没有有效的工具来检测内存泄漏。不过,您可以使用一款软件在 PC 上模拟 IE 6-7-8,它的名称为 IE 测试器

Internet Explorer 最常见的泄漏是与 JScript 的交互。

当 DOM 对象包含引用时
到 JavaScript 对象(例如事件
处理函数),并且当
JavaScript 对象包含一个引用
到那个 DOM 对象,然后是一个循环
结构已形成。

- http://javascript.crockford.com/memory/leak.html

这种循环结构这是 IE 很难处理的问题。您应该了解循环引用是如何形成的(通过闭包)。第一步是在删除 DOM 元素之前清理它们。

这可以通过像这样的通用函数来完成:

function purge(d) {
    var a = d.attributes, i, l, n;
    if (a) {
        l = a.length;
        for (i = 0; i < l; i += 1) {
            n = a[i].name;
            if (typeof d[n] === 'function') {
                d[n] = null;
            }
        }
    }
    a = d.childNodes;
    if (a) {
        l = a.length;
        for (i = 0; i < l; i += 1) {
            purge(d.childNodes[i]);
        }
    }
}

每次从 DOM 中删除元素时,您都需要先对其使用 purge 。您甚至可以为此编写一个包装器。

function safeRemove(el) {
  purge(el);
  el.parentNode.removeChild(el);
}

当然,这只是一个起点,因为它不会帮助您在其他地方(例如 DOM2 事件处理程序,或任何其他地方,尽管闭包)进行引用。您应该检查删除元素的位置,并找出哪些函数引用了它们。

这个问题在IE 6-7-8中似乎仍然存在。

I don't think there is an effective tool to detect memory leaks. There is a piece of software, however, that you can use to emulate IE 6-7-8 on your PC, it's called IE Tester.

The most common leak Internet Explorer had is an interaction with JScript.

When a DOM object contains a reference
to a JavaScript object (such an event
handling function), and when that
JavaScript object contains a reference
to that DOM object, then a cyclic
structure is formed.

- http://javascript.crockford.com/memory/leak.html

This cyclic structure is what IE has hard times dealing with. You should understand how cyclic references are formed (via closure). The first step would be do clean your DOM elements before you remove them.

This can be done by a general function like this:

function purge(d) {
    var a = d.attributes, i, l, n;
    if (a) {
        l = a.length;
        for (i = 0; i < l; i += 1) {
            n = a[i].name;
            if (typeof d[n] === 'function') {
                d[n] = null;
            }
        }
    }
    a = d.childNodes;
    if (a) {
        l = a.length;
        for (i = 0; i < l; i += 1) {
            purge(d.childNodes[i]);
        }
    }
}

Every time you remove elements from the DOM you need to use purge on it first. You can even write a wrapper for that

function safeRemove(el) {
  purge(el);
  el.parentNode.removeChild(el);
}

Of course it's just a starting point, as it won't help you with references in other places (like DOM2 event handlers, or anywhere else though closure). You should check the places where you remove elements, and find out what functions reference them.

This problem seems to still exist in IE 6-7-8.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文