Reputation: 694
I have memory leakage when using Ajax, where Firefox memory usage increases after each ajax call.
I use jQuery 1.10.2.
Are there any workarounds/fixes for this bug?
Edit: I use $.post not $.ajax.
Any $.post function is causing the leak:
$(".Button1").on("click", function(){
$.post(document.location, "data1=1", function(data) {
$("#mainDiv").html(data);
});
});
This is an example code, every time I click on the button memory usage will increase.
Edit2: I have tested this on Chrome too and same problem, so the problem is with jQuery.
I have tried this workaround: http://bugs.jquery.com/ticket/10824
But the problem still exists.
This is more noticable when I run the Ajax function every 10 seconds using setInterval, where memory insanely increases.
Upvotes: 0
Views: 672
Reputation: 694
I have found the cause of the problem, it is html() function, if I use innerHtml the problem is solved.
I think I found a solution on stopping memory leak with html() function:
I save mainDiv object into a variable, then only pass this variable to the $.post:
var main = $("mainDiv");
$(".Button1").on("click", function(){
$.post(document.location, "data1=1", function(data) {
main.html(data);
});
});
And memory leak is reduced to minimum (there is still some slight memory leak but I do not think it is from the code).
Upvotes: 1
Reputation: 658
I think you are loading whole the document in a div, and on the next click again, and so on, so you are not loading the page but the page in a div. What happens if you load data in the document?
Upvotes: 0