IE9内存泄漏 [英] IE9 memory leak

查看:122
本文介绍了IE9内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,在我的应用程序中,与每个页面刷新的Win7上的IE进程相关联的内存增加了20-30 MB。一旦达到约1.5 GB,浏览器就会无法响应。我正在使用IE9,并且只能在IE9中重现这一点。在Chrome,FF,IE7或IE8中没有此类问题。实际上,在兼容模式下运行IE9时也不会出现此问题。

I'm noticing, in my app, the memory associated with the IE process on Win7 climbs by 20-30 MB with each page refresh. Once I reach about 1.5 GB, the browser becomes unresponsive. I'm using IE9, and can only reproduce this in IE9. No such issue in Chrome, FF, IE7, or IE8. In fact, the issue also does not occur when running IE9 in compatibility mode.

特别是,我想知道在页面刷新后内存是如何泄漏的。还有其他人看过这个吗?

In particular, I'm wondering how memory could leak even after a page refresh. Has anyone else seen this?

推荐答案

过去,Internet Explorer在常用JavaScript变量和DOM对象之间的引用方面存在一些问题。所以,如果我没记错的话,像这样的循环引用

In the past, Internet Explorer had some problems with references between usual JavaScript variables and DOM objects. So, if I remember correctly, a circular reference like this

var e = document.createElement('div');
var x = { elementReference: e };
e.jsReference = x;

不会被垃圾收集,即使没有其他对的引用e x 。这是因为IE使用了不同的DOM元素和JavaScript垃圾收集方法。

would not be garbage-collected, even if there were no other references to e and x. This is because IE used different methods of garbage collection for DOM elements and JavaScript.

现在,我相信这个问题已在更高版本的IE中得到纠正,但也许它不是T。如果您不再需要它们,请尝试查找所有此类有问题的引用并手动删除它们。

Now, I believed this problem was already remedied in IEs of higher versions, but maybe it wasn't. Try to find all such problematic references and manually remove them if you don't need them anymore.

e.jsReference = null;
x.elementReference = null;

编辑:在IE 8中测试

我写了这个简单的测试网页。

I wrote this simple test webpage.

<html>
  <head>
    <title>Leak test</title>
    <script>
      function leak() {
        var e = document.createElement('div');
        var x = { elementReference: e };
        e.jsReference = x;
      }

      function test() {
        for (var i = 0; i < 10000; i++)
          leak();
        alert('Done');
      }
    </script>
  </head>
  <body>
    <input type="button" value="test" onclick="test();" />
  </body>
</html>

我在IE 8中测试了这个,因为我没有在这台机器上安装IE 9。但是,这仍然可能是相关的,因为它表明即使在IE的最新版本中问题仍然存在,因此它甚至可能在IE 9中持续存在。

I tested this in IE 8, as I don't have IE 9 installed on this machine. However, this still may be relevant as it shows that the issue was still present even in quite recent versions of IE and thus it may persist even in IE 9.

我打开了页面并观看内存使用情况。每次按下按钮后,内存使用量增加几MB。刷新网页后,绝对没有任何反应。关闭IE之后,内存使用量恢复到原始状态。

I opened the page and watched the memory usage. After each pressing of the button, memory usage increased by several MB. After refreshing the webpage, absolutely nothing happened. After closing IE, the memory usage returned to its original state.

你可以在IE 9中自己尝试一下。当然,你可能没有分配10000个循环引用您的代码中的对象,但您可能会创建更大的对象,其中可能包含一些您尚未找到的循环引用。

You may try that for yourself in IE 9. Of course, you probably aren't allocating 10000 circularily referring objects in your code, but you probably create larger objects that may contain some circular reference you haven't found yet.

这篇关于IE9内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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