泄漏很容易产生。将下面的 HTML 放在名为“TestImage0.jpg”、“TestImage1.jpg”、...“TestImage9.jpg”的大图像列表旁边。每次单击页面时,页面都会泄漏内存(我使用 sIEve 进行测试)。如果resize css被移除,页面不会泄漏。谁能确认这是一个 IE8 问题,或者我的实验有缺陷?
测试代码
<html>
<head>
<title>Memory Leak Testing</title>
<script type="text/javascript">
var count = 0;
window.onload =
function() {
AppendImage();
window.document.body.onclick = ReplaceImage;
}
var ReplaceImage = function() {
window.document.body.removeChild(document.getElementById('MemTestObject' + count));
count++;
if (count > 9) {
alert('No more images to load.');
} else {
AppendImage();
}
}
var AppendImage = function() {
var imageObject = document.createElement('img');
imageObject.id = 'MemTestObject' + count;
imageObject.className = 'MemTestObject';
imageObject.src = 'TestImage' + count + '.jpg';
window.document.body.appendChild(imageObject);
}
</script>
<style type="text/css">
.MemTestObject {
width: 140px;
height: 178px;
}
</style>
</head>
<body>
<h1>Memory Leak Testing</h1>
</body>
</html>