Side navigation
#5285 closed bug (fixed)
Opened September 23, 2009 02:20PM UTC
Closed September 24, 2009 01:37AM UTC
Last modified March 10, 2012 05:31AM UTC
IE7 & IE8 leak memory in jQuery.remove, probably caused by jQuery.data
Reported by: | EliAndrewC | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | data | Version: | 1.3.2 |
Keywords: | memory-leak data event remove | Cc: | |
Blocked by: | Blocking: |
Description
Note: this problem was explored in depth on this Stack Overflow question and answer: http://stackoverflow.com/questions/1462649/jquery-memory-leak-with-dom-removal
I've attached a page which demonstrates a memory leak in remove. Interestingly, this memory leak is caused by the remove function's call to jQuery.event.remove which calls jQuery.data to see whether there are any events.
As documented in the Stack Overflow answer, this call to jQuery.data ends up creating an attribute to store the jQuery.cache id using the value of the expando variable as the attribute name. However, it does this even when we're only reading the data, so if we add a check for this
if (!id && data===undefined)
return undefined
then it makes the memory leak go away. I actually have no idea why this makes the memory leak go away, since the attribute that stores the jQuery.cache id is deleted by the jQuery.removeData function, which is called in remove.
So basically, I have no idea why this memory leak exists, but it definitely does in both IE8 and IE8 compatibility mode (which makes me assume that it also exists in IE7). This problem does not occur in Firefox.
Hopefully my attached proof-of-memory-leak plus the info I've provided will be more enlightening to people more familiar with jQuery's internals.
Attachments (1)
Change History (4)
Changed September 24, 2009 01:37AM UTC by comment:1
resolution: | → fixed |
---|---|
status: | new → closed |
Changed March 14, 2011 11:12PM UTC by comment:2
Hey, did you actually run the test case? If I change it to use 1.5 or 1.5.1 and run it in sieve (with IE 6), I still get the leak? I'm asking because I'm seeing some leaks in IE with Flot, and they mostly seem to come from exactly this use case, appending some stuff to a div and then deleting it afterwards.
One can download sieve here:
Changed March 15, 2011 11:32AM UTC by comment:3
Hm, when I try it outside sieve, I don't seem to be getting the same result. Tried modifying the test case to increase the garbage produced and ran it directly in IE 6, 7 and 8 from the IE Collection. The memory usage is going up and down, but doesn't really seem to increase.
Sorry for the probably false alarm.
Changed July 26, 2011 06:31PM UTC by comment:4
Hi guys, please see this issue again -- I have exactly the same problem with FireFox 5.0.1
I have a table with about 5 rows, each row is loaded by ajax like this:
(each tr has custom attribute "job_id")
$(document).ready(function() {
$(function() {
runJobRowUpdater();
});
});
function runJobRowUpdater() {
var jobRows = $("tr[job_id]");
for (var i = 0; i < jobRows.length; i++) {
var $row = $(jobRows[i]);
var job_id = $row.attr("job_id")
if (job_id) {
updateJobRow(job_id);
}
}
}
function updateJobRow(job_id) {
var $row = $("tr[job_id='" + job_id + "']");
if (job_id) {
$row.load("/jobs/" + job_id + "/row", function() {
setTimeout("updateJobRow( " + job_id + " )", 5000);
});
}
}
So, each 5 seconds each row is loaded by ajax and sets timeout for next 5 seconds and so on.
After half an hour FF reports something like 2GB(!!!!) memory usage
This appears to be fixed in SVN.