I repeatedly retrieve a JSON object from the server using AJAX calls. Over time, memory usage in the browser increases (used with Chrome, Safari, Firefox). Using Chrome heap snapshots, I found that timestamp strings are left without links. If I take a sequence of shots, I see that the number of lines is constantly increasing.
$(function() {
var latestTimestamp = 0;
function fetchData() {
$.get("/parameter?format=json&since=" + latestTimestamp, gotData)
}
function gotData(data) {
latestTimestamp = data['timestamp'];
setTimeout(fetchData, 250);
}
fetchData();
});
Other notes:
- I am using jQuery 1.7.1. EDIT: just tried with 1.6.2 and 1.4.2, the same problem.
timestampin the JSON object is actually an integer, not a string. So cumulative rows can be temporary values?- Removing
+ latestTimestampfrom an AJAX request stops the leak. - setTimeout (20 ) . , , 250 , .