My investigation into a memory leak in a large JavaScript app, running as a widget in a browser with webkit and sfx (JavaScript core engine), led me to discover that the source of memory increase over time was $.ajax(..)
.
I experimented with different versions of jquery
and tried using XMLHttpRequest
directly, but still encountered the same issue. When I tested it on Google Chrome, I was surprised to find that the heap profiler did not show an increase in the number of JS objects or heap size. However, the Chrome task manager did indicate a growth in memory and private memory consumption. The code snippet I used for testing is:
var Main = {};
var xhr = new XMLHttpRequest();
function makeRequest() {
xhr.timeout = 2000;
xhr.ontimeout = function() {
xhr.abort();
}
xhr.onreadystatechange = function() {
if (xhr.readyState != 4) return;
};
xhr.open("POST", "", true); //async post request to local server
xhr.send("{}");
}
Main.onLoad = function()
{
setInterval(function() { makeRequest(); }, 3000);
}
Is this behavior normal? Could it be indicative of a native memory leak?
P.S. I am using Chrome version 35.0.1916.153 on Windows 7 Enterprise.