基于iframe的IE6 javascript内存泄漏? [英] iframe based IE6 javascript memory leak?

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

问题描述

我正在使用iframe通过带有jquery的菜单加载内容,该菜单正在更新
iframe的'src'属性,然后加载到所需的页面中。每个
页面都有自己的javascript包含和重量级内容。

I'm loading in content using an iframe via a menu with jquery which is updating the 'src' attribute of the iframe to then load in the desired page. Each of the pages have their own javascript includes and heavy content.

代码如下: -

$(document).ready(function() {
    loadPage('main.php');
});

function loadPage(url) {
    $('#applicationFrame').attr('src', url);
}

索引页面上的iframe如下所示: -

And the iframe on the index page looks as follows:-

<iframe id="applicationFrame" application="yes" trusted="yes" frameborder="0" />

(旁注:我发现这里的iframe采用了非标准属性,但是
这是一个内部Intranet应用程序,运行在其中一个Microsoft
HTA中,它们确实意味着什么。)

无论如何,菜单item只是在
中调用javascript:loadPage('whatever.php')来加载所需的任何内容。

Anyway, the menu items are just calling javascript:loadPage('whatever.php') in order to load in whatever content is needed.

我面临的问题是在每个后续页面上单击菜单,
帧正在泄漏内存,直到最终整个应用程序慢慢爬行。
sIEve报告以下内容: -

The problem I'm facing is that on each subsequent page click of the menu the frames are leaking memory until eventually the entire app slows to a crawl. sIEve reports the following:-

泄漏http://img37.imageshack.us/img37/3997/leaks.png

泄漏列在这里每个都在上升点击(21 - > 44 - > 65)等。

The leaks column is ascending here with every click (21 -> 44 -> 65) etc.

检查泄漏检查员显示:

检查员http://img527.imageshack.us/img527/4430/inspector.png

在我看来,这只是整个iframed内容已经泄露。

Which looks to me like it is just the entire iframed content which has leaked.

无论如何都有避免这个?我错过了什么吗?我发现了一个类似的问题
这里
dojo框架已经有,但尝试建议的解决方案没有
似乎工作。我还尝试过粘贴
这里的其他一些东西,但没有解决。

Is there anyway to avoid this? Am I missing something? I've found a similar issue here that the dojo framework has had, but trying the suggested solutions hasn't seemed to work. I've also tried a bunch of other things as pasted here but to no resolve.

这似乎(惊喜)影响了IE6,它实际上是应用程序的唯一目标
受众。

This only seems to (surprise) affect IE6 which is really the only target audience of the application.

推荐答案

手头有一点时间,尝试了一个jQuery less变种。根据SIEve,似乎不再泄漏。

Had a little time at hand and tried a jQuery less variant. Doesn't seem to leak anymore according to SIEve.

function pos(obj) {
    var curleft = 0;
    var curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    obj = null;
    return {left:curleft, top:curtop};
}

function loadPage(url) {
    var y = document.getElementById('container');
    var x = document.getElementById('applicationFrame');
    var p = pos(y);
    if (x.src) {
        var tmp = y.cloneNode(false);
        var tmpIF = x.cloneNode(false);
        tmpIF.src = url;
        tmp.appendChild(tmpIF);
        tmp.style.position = 'absolute';
        tmp.style.visibility = 'hidden';
        tmp.style["z-index"] = 20;
        tmp.style.top = p.top;
        tmp.style.left = p.left;
        y.id = "delete";
        x.id = "deleteApplicationFrame";
        document.getElementsByTagName("body")[0].appendChild(tmp);
        tmpIF = null; tmp = null;
    }
    setTimeout("document.getElementById('applicationFrame').style.visibility = 'visible'; var i = document.getElementById('deleteApplicationFrame'); i = i.contentDocument || i.contentWindow.document; i.documentElement.parentNode.removeChild(i.documentElement); i=null; i=document.getElementById('delete'); i.parentNode.removeChild(i); i=null;", 500);
    y = null; x = null; p = null;
}

<div id="container">
    <iframe id="applicationFrame" application="yes" trusted="yes" frameborder="0" src="main.php"/>
</div>






很难说出可能会发生什么不知道整个应用程序。特别是IE6是一个内存泄漏的b..ch。


Very hard to tell what could possibly be going on without knowing the whole application. Especially IE6 is a b..ch with memory leaking.

一些阅读链接

了解并解决Internet Explorer泄漏模式

修复泄漏

Internet Explorer中的内存泄漏 - 重新访问

想一想,AFAIK设置 src时的行为在W3C HTML DOM规范中没有真正指定不同的值,或者是否链接任何人??

Just a thought, AFAIK the behavior when setting src to a different value isn't really specified in the W3C HTML DOM specification or is it (link anyone?)?

我建议你设置一个初始 src =main.php iframe上的值,而不是使用 loadPage('main.php'); 并设置名称iframe。

I suggest that you set an initial src="main.php" value on the iframe instead of using loadPage('main.php'); and set a name for the iframe.

理想情况下,您的菜单项是 < a> 代码然后您可以使用< a href =notmain.phptarget =nameOfYourIFrame> FooBar< / a> 而不是基于javascript的解决方案

Ideally your menu items are <a> tags then you could test using <a href="notmain.php" target="nameOfYourIFrame">FooBar</a> instead of the javascript based solution

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

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