1

I've been racking my brain for the past four days, I've searched, and searched, and found nothing useful. Why does the code below cause a massive memory leak? (400 requests - 130,000 KB)

canLoop = true;
cb = function(){};
xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
    if(xhr.readyState==4){
        cb();
    }
};
function Loop(){
    if(canLoop){
        xhr.open("GET","http://www.roblox.com/User.aspx?id=48103520",true);
        xhr.send();
    }
}
cb = function(){
    console.log(xhr.status);
    setTimeout(Loop,1);
};
Loop();

Please help, I can't understand why this causes a leak. Yes, I did see this thread, and it doesn't appear related. - Memory Leak with an XMLHttpRequest and setInterval Couldn't solve my issue with it, anyway.

Any ideas?

Community
  • 1
  • 1
WebGL3D
  • 454
  • 6
  • 12
  • You might want to add the *complete, reproducible* test setup you were using along with a detailed description of what you did to detect the memory leak. – Tomalak Mar 15 '15 at 18:07
  • How should I give this information? Also, the code I supplied above is a working example. I was using Chrome's Task Manager to watch the memory build up. – WebGL3D Mar 15 '15 at 19:02
  • Well, for starters, provide the exact HTML page, as you use it. Also, the task manager is not the appropriate tool to find memory leaks. Use the [memory profiling tools](https://developer.chrome.com/devtools/docs/javascript-memory-profiling) to measure allocations and heap usage of your script. Do a few test runs in Chrome to determine its behavior, then do a few rounds in Firefox for differential analysis. – Tomalak Mar 15 '15 at 19:50
  • That said, I would write it differently (more like [this](http://pastebin.com/KvXEgJkn)), but I can't see any memory leak with your code on my machine. – Tomalak Mar 15 '15 at 19:55
  • Thanks Tom, I would like to apologize for my question. I was using profiling, but I still couldn't figure it out with that. I just found the real issue, the background page memory was combined with the chrome extension's memory. I always kept the background page open, never thought about closing it.. Thanks for your help anyway, Tom! – WebGL3D Mar 16 '15 at 12:42
  • 1
    There is absolutely no need to apologize. :) – Tomalak Mar 16 '15 at 12:43

0 Answers0