I'm using jQuery 3.1.0 and UWamp 3.1.0 to run this script.
I want to create a script that can connect to a server in order to execute a chain of repetitive tasks; that server doesn't belong to my domain.
I'll post the code only starting from the AJAX calls, as i think they're the ones causing the leaks
This first part connects to a precalculated link and downloads a list of other links to connect to (parser simply returns the content of the given URL).
$.post("php/parser.php", {
url: uri
}, function(res, status) {
// Parsing
The response always contains multiple links, and i need to connect to the first one, execute a few more calls, and only then i can proceed to the second, then the third, etc.
The links are stored in the array urls.
// Connects to the first link in the list
console.log("Request to: " + urls[0]);
urls[0] = $.post("php/parser.php",
{
url: urls[0]
},
function(res, state) {
console.log(0 + ": completed");
}
);
for(var y = 0; y < urls.length;/*y++*/) {
$.when(urls[y]).done(function(res) {
// Other calls here
console.log("Doing stuff");
// Continuing with the next link
y++;
if(y < urls.length) {
console.log("Request to: " + urls[y]);
urls[y] = $.post("php/parser.php",
{
url: urls[y]
},
function(res, state) {
console.log(y + ": completed");
}
);
}
}, function(res) {});
}
});
Now: On Chrome/IE only the first two calls will be executed, since $when(urls[y]).done() is never triggered, as urls[0].state() always equals pending.
On Firefox, if i debug the code everything runs smoothly (spam pressing f10 to step to the next instruction brings an execution time of 6s), whilst if i let the code run on its own, several problems will happen, ranging from console.log() not showing messages, to the browser taking hundreds of megabites out of my RAM each second (whilst progressing extremely slowly), to the point of crashing the browser after about 30s.
A little more precise data, taken from Task Manager; when not executing the script, Firefox uses 480MB of RAM:
debug->up to 500MB of RAM in 6s
run->up to 7GB of RAM in 30s
(I have a lot of other tabs open, if it changes anything)
I'm a complete newbie about js/jQuery/php, and looking online hasn't helped me find any solution; if anyone a little more experienced could spend a little time looking into this, it'd be greatly appreciated. Thanks in advance.
Edit: i solved the problem by making all the calls synchronous, but i'd still be interested in finding the reason the leak happens