如何在IE中强制进行Javascript垃圾回收?在AJAX调用& DOM操作 [英] How can I force Javascript garbage collection in IE? IE is acting very slow after AJAX calls & DOM manipulation

查看:146
本文介绍了如何在IE中强制进行Javascript垃圾回收?在AJAX调用& DOM操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有链式下拉菜单的页面。从第一个选择中选择选项填充第二个,并选择选项从第二个 select 返回一个匹配结果表,使用 innerHtml 函数在空<$ c上页面上有$ c> div 。

I have a page with chained drop-downs. Choosing an option from the first select populates the second, and choosing an option from the second select returns a table of matching results using the innerHtml function on an empty div on the page.

问题是,一旦我做出选择并且有大量数据被带到页面,页面上所有后续的Javascript运行异常缓慢。看起来好像我通过AJAX拉回来填充 div 的所有数据仍在占用大量内存。我在调用 innerHtml 之后尝试将包含AJAX结果的返回对象设置为 null ,但没有运气。

The problem is, once I've made my selections and a considerable amount of data is brought onto the page, all subsequent Javascript on the page runs exceptionally slowly. It seems as if all the data I pulled back via AJAX to populate the div is still hogging a lot of memory. I tried setting the return object which contains the AJAX results to null after calling innerHtml but with no luck.

当我使用Javascript将大量数据插入DOM时,Firefox,Safari,Chrome和Opera都没有显示性能下降,但在IE中它非常明显。为了测试它是一个Javascript / DOM问题而不是一个普通的旧IE问题,我创建了一个页面版本,它返回初始加载的所有结果,而不是通过AJAX / Javascript,并发现IE没有性能问题。

Firefox, Safari, Chrome and Opera all show no performance degradation when I use Javascript to insert a lot of data into the DOM, but in IE it is very apparent. To test that it's a Javascript/DOM issue rather than a plain old IE issue, I created a version of the page that returns all the results on the initial load, rather than via AJAX/Javascript, and found IE had no performance problems.

仅供参考,我正在使用jQuery的jQuery.get方法来执行AJAX调用。

FYI, I'm using jQuery's jQuery.get method to execute the AJAX call.

编辑这就是我正在做的事情:

EDIT This is what I'm doing:

<script type="text/javascript">
function onFinalSelection() {
  var searchParameter = jQuery("#second-select").val();
  jQuery.get("pageReturningAjax.php",
  {SEARCH_PARAMETER: searchParameter},
  function(data) {
    jQuery("#result-div").get(0).innerHtml = data;
   //jQuery("#result-div").html(data); //Tried this, same problem
    data = null;
  },
  "html");
}
</script>

我想注意,这只会在返回数据<时出现问题/ code>非常大。它与大小直接相关,因为我能够看到中等大小结果的适度减速,并且当返回几百条记录时只会出现大幅减速。

I want to note that this only becomes an issue when the return data is quite large. It is directly related to the size, as I am able to see moderate slowdown for medium size results and only major slowdown when it is a few hundred records + being returned.

推荐答案

使用

$("#result-div").html(data);

html()利用jQuery的非常难以防止内存泄漏的方法。

html() utilizes jQuery's empty method which works very hard to prevent memory leaks.

你试过了吗?

delete data;






我认为还有其他性能问题你的代码导致了迟缓。您的返回数据是否使用具有Alpha透明度的png?我已经看到杀死IE6(当应用alpha过滤器时)并大大减慢IE7。


I'm thinking there are other performance issues in your code causing the sluggishness. Is your return data using png's with alpha transparency? I've seen that kill IE6 (when the alpha filter is applied) and slow down IE7 considerably.

这篇关于如何在IE中强制进行Javascript垃圾回收?在AJAX调用&amp; DOM操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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