Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I found a memory leak in the following code (the else block)
JavaScript
if (browser == "Microsoft Internet Explorer"){
    if (vers < 7){
        document.getElementById("theData").src = "data.js";
    }else{
            xmlHTTP = new XMLHttpRequest();
            xmlHTTP.open('GET', "data.js", false);
            xmlHTTP.send(null);
            eval(xmlHTTP.responseText);
            window.execScript(xmlHTTP.responseText);
            xmlHTTP = null;
            delete xmlHTTP;
    }
}else{
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'data.js';
    document.getElementsByTagName('head')[0].appendChild(script);
}//end if
refreshCount=0;

Your help is appreciated!
Posted

1 solution

I don't think you can do anything about it.

Are you sure you really detected the leak? How? Not all methods are reliable. Anyway, if you do have a leak, you cannot prevent it. All complains go to Microsoft :-(

—SA
 
Share this answer
 
Comments
Sameer Alomari 26-Mar-13 17:52pm    
if I comment xmlHTTP.send(null); then the memory is stable! any clue?
Sergey Alexandrovich Kryukov 26-Mar-13 19:06pm    
I don't know. Garbage in — garbage out. Why would anyone send null in HTTP request?
Anyway, the host system, in this case, IE7 should not allow leaks, no matter what happens in JavaScript code. So, my question is: what kind of leak and how you detect it?
Does the memory use grow in unlimited manner if you repeatedly do the HTTP request? Does to grow is you reload the same page several time and do HTTP request? And how do you measure it?
—SA
Sameer Alomari 27-Mar-13 16:17pm    
This code is called by a timer every second to pull data.js file from the server, So I get a leak because the application calls this code constantly
Sergey Alexandrovich Kryukov 27-Mar-13 16:38pm    
Well, I do understand what happens when you have a leak, I'm still not sure you have it... Anyway, use the memory debugger.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900