锁定老帖子 主题:IE内存泄露
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (1)
|
|
---|---|
作者 | 正文 |
发表时间:2008-12-25
最后修改:2011-06-09
<html> <head> <script language="JScript"> var jsObject; function SetupLeak() { jsObject = document.getElementById("LeakedDiv"); document.getElementById("LeakedDiv").expandoProperty = jsObject; } </script> </head> <body onload="SetupLeak()"> <div id="LeakedDiv"></div> </body> </html> 参考:http://blogs.msdn.com/gpde/pages/javascript-memory-leak-detector.aspx 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-12-25
IE7已经解决了
|
|
返回顶楼 | |
发表时间:2008-12-25
javaeyebird 写道 IE7已经解决了
你在IE7重复刷新看看。 |
|
返回顶楼 | |
发表时间:2008-12-25
The IE team has been working hard to solve the problem. With the initial versions of Internet Explorer 6 practically all circular references between Javascript and DOM objects caused a memory leak. Avoiding leaks was not an easy task even because there are language constructs, like JavaScript closures, that make particularly difficult to track down those circular references.
IE小组及京开始研究此问题了,在最初的ie6版本中,任何的js引擎和DOM(COM)引擎间的循环引用都会泄漏,解决这个泄漏也不是那么容易,语言中比如说闭包都是地发现交叉循环引用困难重重。 Internet Explorer 7 improved the situation by releasing all references to JavaScript objects attached to the DOM tree when IE navigates away from that page. This allows the JavaScript engine to garbage collect those JavaScript objects and recover that memory. Almost the same changes were also shipped with the latest security updates of IE6. So, the previous code does not actually leak anymore. ie7开始改进了局面,在用户从本用浏览器转移浏览路径时候,会释放绑定dom上的js对象,使得js的gc可以回收资源。所以你的代码已经不泄漏了 However, as some web developers have pointed out, those changes did not solve the problem entirely. IE still leaves behind anything not attached to the tree when the markup is tore down. The previous script, for example, would still leak if the LeakedDiv object was detached from the markup of the page calling: 然而,就是一些家伙指出的,问题远远不那么简单,ie的改进只是对于页面dom树上对象进行清除js引用的动作,对于使用removeChild删除的dom对象那些已经不在页面上但是却还是有js引用的ie7也是无能为力的 LeakedDiv.parentElement.removeChild(LeakedDiv); 所以记住这句万恶的remove,记住要 LeakedDiv.expandoProperty=null; LeakedDiv.parentElement.removeChild(LeakedDiv); 才可以,其实即使这样使用Drip看还是有5个引用在LeakedDiv上,是不是泄漏不好说了,目前看来,ie上面较好的办法就是还是先别用removeChild了 另外,标题不好,ie是很成功的产品,没有他就没有你的工作 |
|
返回顶楼 | |
发表时间:2008-12-26
最后修改:2008-12-26
<script language="JScript"> 我又迷糊了:Jscript和JavaScript是一样的吗? ps;我刷新也没有出现错误,弱弱的问下:ie里咋看泄露啊? |
|
返回顶楼 | |
发表时间:2008-12-26
最后修改:2008-12-26
hite 写道 <script language="JScript"> 我又迷糊了:Jscript和JavaScript是一样的吗? ps;我刷新也没有出现错误,弱弱的问下:ie里咋看泄露啊? 看了afcn0给的链接,我知道了上面的代码是作者拷过来! 看来lz不严谨啊,写的tag是JavaScript里面给的是jscript的代码.。 害的小白在这里犯迷糊。 后面的问题也知道了,就是下那个插件。可惜是个死链! |
|
返回顶楼 | |
发表时间:2008-12-26
afcn0 写道 The IE team has been working hard to solve the problem. With the initial versions of Internet Explorer 6 practically all circular references between Javascript and DOM objects caused a memory leak. Avoiding leaks was not an easy task even because there are language constructs, like JavaScript closures, that make particularly difficult to track down those circular references.
IE小组及京开始研究此问题了,在最初的ie6版本中,任何的js引擎和DOM(COM)引擎间的循环引用都会泄漏,解决这个泄漏也不是那么容易,语言中比如说闭包都是地发现交叉循环引用困难重重。 Internet Explorer 7 improved the situation by releasing all references to JavaScript objects attached to the DOM tree when IE navigates away from that page. This allows the JavaScript engine to garbage collect those JavaScript objects and recover that memory. Almost the same changes were also shipped with the latest security updates of IE6. So, the previous code does not actually leak anymore. ie7开始改进了局面,在用户从本用浏览器转移浏览路径时候,会释放绑定dom上的js对象,使得js的gc可以回收资源。所以你的代码已经不泄漏了 However, as some web developers have pointed out, those changes did not solve the problem entirely. IE still leaves behind anything not attached to the tree when the markup is tore down. The previous script, for example, would still leak if the LeakedDiv object was detached from the markup of the page calling: 然而,就是一些家伙指出的,问题远远不那么简单,ie的改进只是对于页面dom树上对象进行清除js引用的动作,对于使用removeChild删除的dom对象那些已经不在页面上但是却还是有js引用的ie7也是无能为力的 LeakedDiv.parentElement.removeChild(LeakedDiv); 所以记住这句万恶的remove,记住要 LeakedDiv.expandoProperty=null; LeakedDiv.parentElement.removeChild(LeakedDiv); 才可以,其实即使这样使用Drip看还是有5个引用在LeakedDiv上,是不是泄漏不好说了,目前看来,ie上面较好的办法就是还是先别用removeChild了 另外,标题不好,ie是很成功的产品,没有他就没有你的工作 IE商业上成功不代表它的程序质量也好。 |
|
返回顶楼 | |
发表时间:2008-12-26
hite 写道 hite 写道 <script language="JScript"> 我又迷糊了:Jscript和JavaScript是一样的吗? ps;我刷新也没有出现错误,弱弱的问下:ie里咋看泄露啊? 看了afcn0给的链接,我知道了上面的代码是作者拷过来! 看来lz不严谨啊,写的tag是JavaScript里面给的是jscript的代码.。 害的小白在这里犯迷糊。 后面的问题也知道了,就是下那个插件。可惜是个死链! IE里没有javascript,只有Jscript。 |
|
返回顶楼 | |
发表时间:2008-12-26
hite 写道 <script language="JScript"> 我又迷糊了:Jscript和JavaScript是一样的吗? ps;我刷新也没有出现错误,弱弱的问下:ie里咋看泄露啊? 打开任务管理器,看ie进程的内存。 |
|
返回顶楼 | |
发表时间:2008-12-26
lz听谁说IE里没有javascript,只有Jscript?难道你写成language="JavaScript",ie就不认了?。现在说的javascript一般是指ECMAScript,国际统一标准的javascript。所有主流的浏览器都支持,当然也包括IE
|
|
返回顶楼 | |