I am making an AJAX request for XML. I am doing this every second. I notice that my memory usage grows into the hundreds of megabytes. As you might imagine, the customer is not happy with this. After doing some reading in various places, I suspect that function closures are causing my headache. I am looking for any verification that can be had as well as any help for how to fix it.
function PageManager () {
var self = this;
self.timeoutHandler = function () {
$.ajax ({
url: 'URLtoXML',
type: 'post',
cache: false,
context: self,
success: function (data) {
var slf = this;
var xmlDoc = $($.parseXML (data));
xmlDoc.find ("tag_label").each (function () {
self.val = parseInt ($.trim ($(this).text ()));
}
setTimeout (slf.timeoutHandler, 750);
}
});
}
}
var pm = new PageManager ();
pm.timeoutHandler ();
EDIT I have incorporated some people's ideas and a little of the success handler internals. I see a smaller growth rate, but not by much.