style.filter导致内存泄漏? [英] style.filter causing memory leak?

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

问题描述

在下面的代码清单中,IE内存使用量(由perfmon监控)逐渐增加,除非我删除该行:

 newIcon.style.filter = "alpha(opacity = 50)"; 

应用任何类型的过滤器(甚至设置filter = null!)都会导致此泄漏。我需要
能够一遍又一遍地创建DOM对象(即IMG),将
应用于不透明度过滤器,然后在一些短的
间隔后销毁对象。



我意识到它存在的脚本有点人为。在实践中,
的间隔不会触发几乎同样快。但是,如果你想花费
时间来玩它,你会发现以
更合理的间隔(每30秒)运行脚本仍会导致内存
泄漏。它只需要更多的时间。



如果你想运行这个脚本,你需要一个小的gif图像在与其上有脚本的页面相同的目录中。



先谢谢!

<!DOCTYPE html public"  -  // W3C // DTD XHTML 1.0 Transitional // EN" 
" http://www.w3.org/TR/xhtml1/DTD /xhtml1-transitional.dtd">
< html xmlns =" http://www.w3.org/1999/xhtml">

< head>
< title> Sample Leak< / title>
< script type =" text / javascript">

function buildIcon(counter){

var newIconId = counter;
//创建一个新的div
var newIcon = document.createElement(" IMG");

var newIconId = newIconId +" Div" ;;
newIcon.setAttribute(" id", newIconId);
newIcon.src =" bed.gif" ;;
newIcon.style.top = counter * 2 +" px" ;;
newIcon.style.left = counter * 2 +" px" ;;
newIcon.style.height =" 20px" ;;
newIcon.style.width =" 20px" ;;
n ewIcon.style.filter =" alpha(opacity = 50)" ;;
newIcon.style.position =" absolute" ;;

document.getElementById(" canvas")。appendChild(newIcon );

//将img排队以便稍后发布

































];

函数cleanUpOldIcons(){
for(var j = deadIcons.length - 1; j> = 0; j--){
//首先获取元素的父元素
var node = deadIcons [j];

var parent = node.parentNode;
if(parent){
parent.removeChild(node);
}





























cleanUpOldIcons();


(var i = 0; i< 100; i ++){

buildIcon(i);

}

}

function load(){

var interval = setInterval(" buildIcons();",100);





< / script>
< / head>

< body onload =" load();">

< div id =" canvas" style =" top:0px; left:0px; width:500px; height:500px;">

< / div>

< / body>
< ; / html>


解决方案

我也检测到了泄漏设置样式。


我认为现在有好的证据表明IE已经确认了泄漏设置样式。


http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/螺纹/ c440c66f-4701-405d-8747-860787ecdc95


In the code listing below, IE memory usage (as monitored from perfmon) gradually increases over time unless I remove the line:

newIcon.style.filter="alpha(opacity=50)";

It appears that applying any sort of filter (even setting filter=null!) causes this leak. I need to be able to create DOM objects (IMG's namely) over and over again, apply an opacity filter, and then destroy the objects after some short interval.

I realize that the script as it exists is a bit contrived. In practice, the interval doesn't trigger nearly as fast. If you want to take the time to play with it, however, you'll see that running the script at a more reasonable interval (every 30 seconds), will still cause a memory leak. It just takes more time.

If you want to run this script, you'll need a small gif image in the same directory as the page with the script on it.

Thanks in Advance!

<!DOCTYPE html public "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Sample Leak</title>
<script type="text/javascript">

function buildIcon(counter) {

var newIconId = counter;
//create a new div
var newIcon = document.createElement("IMG");

var newIconId = newIconId + "Div";
newIcon.setAttribute("id", newIconId);
newIcon.src = "bed.gif";
newIcon.style.top = counter * 2 + "px";
newIcon.style.left = counter * 2 + "px";
newIcon.style.height="20px";
newIcon.style.width="20px";
newIcon.style.filter="alpha(opacity=50)";
newIcon.style.position="absolute";

document.getElementById("canvas").appendChild(newIcon);

//Queue up the img for release later
deadIcons.push(newIcon);



}

var deadIcons = [];

function cleanUpOldIcons() {
for (var j = deadIcons.length - 1; j >= 0; j--) {
//first get the element's parent
var node = deadIcons[j];

var parent = node.parentNode;
if (parent) {
parent.removeChild(node);
}

}

deadIcons = [];
}

function buildIcons() {

cleanUpOldIcons();

for (var i = 0; i < 100; i++) {

buildIcon(i);

}

}

function load() {

var interval = setInterval("buildIcons();", 100);

}


</script>
</head>

<body onload="load();">

<div id="canvas" style="top:0px;left:0px;width:500px;height:500px;">

</div>

</body>
</html>


解决方案

I have detected a leak setting style as well.

I think that there is now good evidence that IE has a confirmed leak setting styles.

http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/c440c66f-4701-405d-8747-860787ecdc95


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

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