I am repeatedly fetching a JSON object from the server with AJAX calls. Over time, the memory usage of the browser grows (tried with Chrome, Safari, Firefox). Using Chrome's heap snapshots, I've discovered that the timestamp strings are being left around with no references. If I a take a sequence of snapshots, I see the number of Strings is continually 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:
timestamp
in the JSON object is actually an integer, not a string. So the accumulating strings might be temporary values?+ latestTimestamp
from the AJAX request stops the leak. Did you try cleartimeout javascript function ? if not please try this.
var abc=null;
function gotData(data) {
latestTimestamp = data['timestamp'];
data=null;
clearTimeout(abc);
abc=setTimeout(fetchData, 250);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With