Why is this javascript updating the memory leak?

I have a dashboard on my TV and the page needs to refresh every second.

At the bottom of the page, I have:

function startRefresh() {
    $.get('', function(data) {
        var newDoc = document.open("text/html", "replace");
        newDoc.write(data);
        newDoc.close();
    });
}
$(function() {
    setTimeout(startRefresh,1000);
});

      

This works great, except that each page load causes memory usage to increase by reporting chrome://memory-redirect/

.

Is there a way to fix this? I'm not interested in creating a separate page for the DIV and just reloading that part.

FYI HTTP header updates and document.location = document.location

both of them become flicker-less

+3


source to share


2 answers


If you are using Chrome, you must use "Timeline" to record memory usage. Run the timeline, then wait for the page to refresh a few times, then stop the graph and see the results. If you see the line continues to grow, it means that your objects in memory (or DOM nodes) are never released and garbage collected.

I've never used it document.open/write

myself, so I don't know if this could cause garbage collection problems, but I suspect it does.



If you can clearly define memory using the timeline, open the Profiles tab and take a Heat before and after page reloads, then use Compare to see what has changed and how much greater your memory impact is. If, for example, your old compiled code (or references to obejct) is still there, plus the new one, then it explains your leak.

+1


source


Have you tried location.reload () ?

function startRefresh() {
    location.reload();
}
$(function() {
    setTimeout(startRefresh,1000);
});

      



EDIT: After re-reading the question, I understand that you did not ask for an alternative method, but explained the memory leak (which I do not have).

0


source







All Articles