XMLHttpRequest garbage collector

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dasty
    Recognized Expert New Member
    • Nov 2007
    • 101

    XMLHttpRequest garbage collector

    Hello,

    I got one question, that may seems trivial to you, but I really dont understand it. Let's say we got this code:

    [PHP]
    function ajax()
    {
    var obj;
    obj = new ActiveXObject(" Microsoft.XMLHT TP");
    obj.onreadystat echange = function ()
    {
    [anycode];
    };
    obj.open("GET", "http://www.park.sk", true);
    obj.send(null);
    }
    [/PHP]

    (for simplicity i created XHR just for IE as activex). As far as I know, browsers's garbage collector should discard all function's local variables after functions exits, if none of inner objects (variables) got reference out of that function. But as we all know, XHR object persists in memory and becuase it refers to locally created function (onreadystatech ange), all local varibales stay in memory as well (because of closures). But why does garbace collector not discard activex object after function ajax exits? It does not have any reference out of that function's scope.

    It looks like that browser creates some hidden reference to that activex object AFTER i call "send" method (so browser wont discard it), and delete that reference after XHR objects's state change to LOADED.

    Please make it clear to me. I really cant find the answer.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    I'm not too sure about IE's (or other browsers') garbage collection methods, but you could set the variable to null if it's causing a problem.

    Comment

    Working...