onClick ='foo()',至少需要个指向函数的指针吧,指针也占用内存空间,所以....
以上是个人意见.
以上是个人意见.
解决方案 »
- 求助关于ajax验证数据防止提交的问题
- 怎么将带参数的函数绑定到某个页面组件的点击事件上?
- js能否定义索引数组
- 在火狐下如何实现xmlDocument的selectSingleNode
- jscript读取文件信息时出错的问题!(使用wsh运行.js文件)
- 天天问,问题天天出,又有新问题,最好给出错误改成正确的
- 很多论坛为防止用户上传 javascript 语句,在用户提交文本时把“<”转换为“<”请问有什么办法能提交“<"吗?
- 怎么过滤文件后缀<input type="file"> 让他只显示*.jpg和*.gif
- JS里绝对值的函数是什么?
- 一个简单的web登录技术问题!
- 菜鸟提问!!求算法!已知a,b,现在点鼠标a会向b游动,鼠标停,a会停下来
- 关于IE下的内存回收研究.
var div1 = document.createElement("DIV");
var div2 = document.createElement("DIV");
div1.appendChild(div2);
document.body.appendChild(div1);
这样的话,无论怎么的插入顺序也不会有内存泄漏吧。
<div id="hostElement">
</div>
<script language=javascript>
function foo()
{
}
function LeakMemory()
{
var hostElement = document.getElementById("hostElement"); // Do it a lot, look at Task Manager for memory response for(i = 0; i < 5000; i++)
{
var parentDiv =document.createElement("<div>");
//document.createElement("<div onclick='foo()'>");
parentDiv.onclick=foo;
var childDiv =document.createElement("<div>");
//document.createElement("<div onclick='foo()'>");
childDiv.onclick=foo; // This will leak a temporary object
parentDiv.appendChild(childDiv);
hostElement.appendChild(parentDiv);
hostElement.removeChild(parentDiv);
parentDiv.removeChild(childDiv);
parentDiv = null;
childDiv = null;
}
hostElement = null;
alert("done")
}
LeakMemory();
</script>
parentDiv.appendChild(childDiv);
hostElement.appendChild(parentDiv);
hostElement.removeChild(parentDiv);
parentDiv.removeChild(childDiv);这几句注释掉才恐怖呢。离开页面内存都不能释放。连刷几次就占光你内存了。