使用JavaScript的Internet Explorer,如何清除内存而无需刷新页面? [英] Using JavaScript with Internet Explorer, how do I clear memory without refreshing the page?

查看:175
本文介绍了使用JavaScript的Internet Explorer,如何清除内存而无需刷新页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JavaScript客户端上的基于AJAX的网站。从浏览器调用服务站点缓存大结果集的某些操作(如几百兆)。这些被扔掉的结果。它们将被视为很短的时间,然后需要从存储器中清除。

I have an AJAX-based website using JavaScript on the client. Certain operations on the site cache large result sets from service calls in the browser (i.e. hundreds of megabytes). These are throw-away results. They will be viewed for a short time and then need to be cleared from memory.

我写了一个小的测试网站加载了一堆垃圾在内存中,然后调用JavaScript的删除方法。这在Firefox的伟大工程(内存几乎是瞬间被返回)。 Internet Explorer 8中(没试过7)不释放内存,直到页面刷新或关闭。

I've written a small test site that loads a bunch of junk in memory and then calls JavaScript's delete method. This works great in Firefox (memory almost instantly gets returned). Internet Explorer 8 (haven't tried 7) doesn't free the memory until the page is refreshed or closed.

有谁知道怎么滴使用JavaScript / AJAX(无页面刷新)?IE浏览器的内存占用

Does anyone know how to drop IE's memory usage using JavaScript/Ajax (no page refreshes)?

下面是我的样本客户端code:

Below is my sample client code:

function load() {
 var x = ['dfjasdlfkjsa;dflkjsad;flkjsadf;lj'];

 for( var i = 0; i < 10000000; ++i ) {
  x.push('asdfasfasfsfasdfkasjfslafkjslfjsalfjsaldfkjasl;dfkjsadfl;kjsdflskajflskfjslakfjaslfkjsaldfkjsaldfksdfjk');
 }

 alert('deleting');   // <--- memory usage around 500mb
 delete x;            // <--- immediate results in Firefox 3.5 (not IE8)
 alert('done');
}

更新:将该变量设置为'空'不立即清除内存(因为这是留给垃圾收集器)。此外,设置变量空只得到一个参考,其中可能有多个引用。

UPDATE: Setting the variable to 'null' does not immediately clear the memory (as that is left up to the garbage collector). Also, setting a variable null only gets a single reference where there might be multiple references.

推荐答案

IE(当然,从技术上说,JScript的)具有的一个无证 Col​​lectGarbage ,据称力垃圾收集器立即运行。您可能希望与该打,但是从我的经验, ING引用是足够的大部分时间。

IE (well, technically, JScript) has an undocumented CollectGarbage method, which supposedly forces garbage collector to run immediately. You might want to play with that, but from my experience, nulling references is enough most of the time.

这篇关于使用JavaScript的Internet Explorer,如何清除内存而无需刷新页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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