在Javascript中的IE和内存累积 [英] IE and Memory accumulation in Javascript

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

问题描述

以下是测试网址

http: //edventures.com/temp/divtest.php

程序:


  1. 关闭所有IE实例。

  2. 在IE7中打开URL

  3. 打开任务管理器,查找IE消耗的内存

  4. 现在点击创建按钮,

  5. 观察内存大约会增加2K

  6. 现在点击销毁按钮和DIV将被销毁,但内存保持不变。

  7. 您可以反复尝试,内存只会加起来。

  1. Close all IE instances.
  2. Open the URL in IE7
  3. Open the task manager, look for memory consumed by IE
  4. Now click on Create button,
  5. Watch the memory it will jump up by about 2K
  6. Now click on Destroy button and the DIV will be destroyed but the memory remains the same.
  7. You can try it repeatedly and memory just adds up.

有什么方法可以解决这个问题吗?有没有办法在不重新加载窗口的情况下强行调用垃圾收集器?

Is there any way to fix this? Any way to call Garbage collector forcefully without reloading the window?

我假设当我删除DIV时,内存将被释放,但似乎没有那样工作。

I am under assumption that when I remove DIV the memory will be freed but does not seem to work that way.

请告诉我任何解决方法。

Please let me know any fix to this.

感谢您的帮助。

Suhas

推荐答案

以下是如何在IE中创建DOM元素并防止内存泄漏。

Here's how to create DOM elements and prevent memory leaks in IE.

function createDOMElement(el) {
  var el = document.createElement(el);

  try {
    return el;
  }
  finally {
    el = null;
  }
}

您可以使用try / finally技巧的变体来在执行其他DOM操作时防止泄漏。

You can use variations of the try/finally trick to prevent the leaks when doing other DOM operations.

这篇关于在Javascript中的IE和内存累积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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