Why would this javascript be causing browser crashes from memory usage?
It is looking like i have a major memory leak in this little bit of javascript. I'm hoping someone might be able to point me in a direction to possibly be a little more memory efficient, and not cause browser crashes.
This javascript is running on a page that is up on a system constantly. It gets an applciation out of memory exception after about a week of continuous running.
Any suggestions for making this more efficient? What part of this is causing the leak?
setInterval("$.get('Dashboard.aspx', function (data)
{
$('#buildMonitorBody').html(data);
});"
, 300000);
As always, I appreciate any help that 开发者_StackOverflow社区can be given.
From my understanding, web pages are not meant to stay open permanently - for such thing you have background processes or windows services.
If you do have to stick with this wrong approach, my tip would be to force reload every day with such code:
window.setTimeout(function() {
document.location.href = document.location.href;
}, 1000 * 60 * 60 * 24);
Hopefully reloading the page will release the memory reserved for the numerous timer calls.
Passing a string to setInterval over and over is probably the cause of the memory leaks (possibly not being garbage collected). Try doing this:
var loadDashboard = function() {
$('#buildMonitorBody').load('Dashboard.aspx');
};
setInterval(loadDashboard, 300000);
You can use .load
to simplify your ajax request.
精彩评论