javascript IE6/7/8 内存不足?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3910044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 02:39:42  来源:igfitidea点击:

IE6/7/8 Out of Memory?

javascriptjqueryinternet-explorermemoryiframe

提问by Collin Klopfenstein

I was doing some cross browser testing on certain piece of functionality today, and ran across a rather nifty little gem.

我今天正在对某些功能进行一些跨浏览器测试,并且遇到了一个相当漂亮的小宝石。

In IE8: Out of memory at line: 99

在 IE8 中: Out of memory at line: 99

In IE7: Out of memory at line: 100

在 IE7 中: Out of memory at line: 100

In IE6: Stack overflow at line: 101

在 IE6 中: Stack overflow at line: 101

From what I've been able to dig up, most of the time these messages start appearing, it's an issue with having an array in which the number of elements is greater than 65,535. However, I don't believe that that's the issue at hand here.

据我所知,大多数情况下这些消息开始出现,这是一个数组的问题,其中元素的数量大于65,535. 但是,我不认为这是当前的问题。

The functionality in question is an action from within an iframe"closing" the current iframeand "opening" another using jQuery. It's actually happening on the close/open interaction.

有问题的功能是使用 jQuery在iframe“关闭”当前iframe和“打开”另一个中的操作。它实际上发生在关闭/打开交互中。

Has anyone seen anything like this before?

有没有人见过这样的事情?

Edit: Upon further investigation, it doesn't actually seem to be related to the iframes. Still digging, but any suggestions would be appreciated.

编辑:经过进一步调查,它实际上似乎与 iframe 无关。仍在挖掘,但任何建议将不胜感激。

采纳答案by Collin Klopfenstein

So it turned out to be an issue with IE and everything else handling things differently...as usual.

所以结果证明是 IE 和其他一切以不同方式处理事情的问题......像往常一样。

I have a function that I'm using to throw an error, and it's recursive by design. I wanted the error to be displayed in the main Document, not an iframe (which are being used extensively on this site, unfortunately). The gist of my function is as follows:

我有一个用于抛出错误的函数,它是按设计递归的。我希望错误显示在主文档中,而不是 iframe(不幸的是,它在本网站上被广泛使用)。我的功能的要点如下:

myClass.myErrorFunc = function ( msg ) {
    if ( parent !== window ) {
        parent.myClass.myErrorFunc( msg );
    } else {
        // display the error
    }
}

This works GREAT in Chrome and Firefox. It recurses one level and does the error displaying in the main window because once it gets to the top level, the parent is itself. Apparently in IE, however, window's parent is NEVER itself. Thus, infinite recursion.

这在 Chrome 和 Firefox 中非常有效。它递归一级并在主窗口中显示错误,因为一旦到达顶层,父级就是它自己。然而,显然在 IE 中,窗口的父级从来不是它本身。因此,无限递归。

Stay tuned for a solution.

请继续关注解决方案。

Edit:Apparently, it was an issue with using !==instead of !=. When I switched it to !=, the second time through (as this is being run from an iframe), window == parentevaluates true, but window === parentdoes not...

编辑:显然,使用!==而不是!=. 当我将它切换到 时!=,第二次通过(因为这是从 运行iframe),window == parent评估为真,但window === parent不......

Whatever, I'll take it...

无论如何,我会接受...

Thanks for your help guys.

谢谢你们的帮助。

回答by Boris Hamanov

It would seem that you take too much memory with something and IE does not have so much memory allocated for that kind of something :) Other browsers do. If you take a look at those line numbers that you have or debug your code with IE8 developer tools you should get your answer.

看起来您使用某些东西占用了太多内存,而 IE 没有为这种东西分配这么多内存:) 其他浏览器可以。如果您查看您拥有的那些行号或使用 IE8 开发人员工具调试您的代码,您应该会得到答案。

If it is not a recursion it may be a loop that keeps eating more memory until it runs out.

如果它不是递归,它可能是一个循环,它会不断消耗更多内存,直到用完为止。