Wow, I wasn't aware of this memory leak at all. Thanks for bringing it
to my attention. I had no idea that storing the current element in a
variable would cause a leak. That's a really common thing to do in
jQuery plugins. I wonder if the memory issue has been encountered in
other plugins and how it has been dealt with.
--Karl
____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On Oct 22, 2009, at 7:49 PM, Andrew Tan wrote:
Hi,
I have been tracking down a memory leak in my web app which
dynamically removes and adds anchors which have cluetip tooltips
attached and I think that I may have narrowed down the problem to the
main closure in cluetip which attaches the cluetip to the node (line
32: var link = this, $this = $(this);).
I have been running the following script in SIEV with a modified
version of jquery 1.3.2 with the following fix which allows the
cluetip elements to be removed. However, the anchor nodes become
orphaned as there is still 1 reference to them after the cluetip nodes
are removed?
If I change line 32 of the cluetip source to the following for testing
purposes:
var link = $('br'), $this = $('br');
The anchors are freed but the 'br' nodes start building up.
Therefore, I was wondering if anyone knows how I can work around this
problem? or if I am simply not releasing the resources correctly?
Attached Scripts and Source:
jQuery modification. After line 1247 insert the following before the
closing curly brace (http://markmail.org/message/
cfi4bvfjc3m6ww6k#query:jquery%20memory%20leak%20in%20remove%20and
%20empty+page:1+mid:tapc7zt3cwl6rw4f+state:results):
this.outerHTML = "";
Example Script:
<html>
<head>
<link rel="stylesheet" type="text/css" href="jquery.cluetip.css"/>
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript" src="jquery.cluetip.js"></script>
<script type="text/javascript">
$(document).ready(function() {
setInterval(resetCluetip, 1000);
});
function resetCluetip() {
$('a').each(function() {
$(this).cluetip('destroy');
$(this).unbind().remove();
});
$('#cluetip*').unbind().empty();
$('body').html('<a href="#" class="contextMenu"
title="title|
body">anchor one</a><br>');
$('a').each(function() {
$(this).cluetip({splitTitle: '|'});
});
}
</script>
</head>
<body>
</body>
</html>