问题描述
我正在开发一个大量使用jquery(UI)来提供良好用户体验的网站。对于一些(愚蠢的)原因,本网站的部分内容显示在iframe中,还有一个按钮用于刷新iframe以从服务器获取最新数据。
问题是,每次刷新iframe时,内存使用量增加会导致严重的内存问题(经过IE8和9测试)。但是,只有加载jquery库时才会发生这种情况。使用时,可以最好地看到此行为。为了更好地理解问题,我删除了导致以下两个文件的所有不必要的代码。每次重新加载时,内存使用量增加约800 kb。 (如果要复制,请尝试)
我如何防止jquery吃掉我的记忆?有没有办法在重新加载之前手动卸载所有jquery?
index.htm :((参见)
< html>
< head>
< title>内存泄漏 - 父< / title>
< script type =text / javascript>
函数reload(){
var frame = document.getElementById(testFrame);
frame.src =frame.htm;
}
< / script>
< / head>
< body>
< a href =javascript:reload()id =link> reload frame< / a>
< iframe id =testFramesrc =frame.htm/>
< / body>
< / html>
frame.htm:(请参阅)
< html>
< head>
< title>内存泄漏 - 帧< / title>
< script type =text / javascriptsrc =http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js>< / script>
< / head>
< body>
< h2>测试帧< / h2>
< div> lorem ipsum< / div>< div> ; / div>< div> lorem ipsum< / div>
< / body>
< / html>
实验一个或多个以下内容: p>
- 使用对象元素而不是iframe
- 操纵
- 使用
I am developing a site which heavily uses jquery (UI) for providing a good user experience. For some (stupid) reason parts of this site are shown within an iframe and there also is a button for refreshing the iframe to get the latest data from the server.
The problem is that each time when refreshing the iframe the memory usage increases leading to serious memory problems after some time (Tested in IE8 & 9). But this occurs only if the jquery library is loaded. This behaviour can be seen best when using Drip/Sieve. For better understanding the problem I stripped off all unnecessary code leading to the two files below. With each reload the memory usage increases about 800 kb. (try http://jsbin.com/asamid/7 if you want to reproduce)
How can i prevent jquery from eating away my memory? Is there a way to manually unload all jquery before reloading?
index.htm: (see http://jsbin.com/asamid/7/edit#html,live)
<html>
<head>
<title>Memory Leak - Parent</title>
<script type="text/javascript">
function reload() {
var frame = document.getElementById("testFrame");
frame.src = "frame.htm";
}
</script>
</head>
<body>
<a href="javascript:reload()" id="link">reload frame</a>
<iframe id="testFrame" src="frame.htm" />
</body>
</html>
frame.htm: (see http://jsbin.com/ocuval/edit#html,live)
<html>
<head>
<title>Memory Leak - Frame</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>
<body>
<h2>Test Frame</h2>
<div>lorem ipsum</div><div>lorem ipsum</div><div>lorem ipsum</div><div>lorem ipsum</div><div>lorem ipsum</div><div>lorem ipsum</div>
</body>
</html>
Experiment with one or more of the following:
- Use an object element instead of an iframe
- Manipulate $.fragments
- Create an iframe dynamically using the jQuery constructor
这篇关于使用jquery增加内存使用量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!