By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,516 Members | 1,126 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,516 IT Pros & Developers. It's quick & easy.

XMLHttpRequest garbage collector

Expert 100+
P: 101

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

function ajax()
var obj;
obj = new ActiveXObject("Microsoft.XMLHTTP");
obj.onreadystatechange = function ()
};"GET", "", true);

(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 (onreadystatechange), 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.
Nov 11 '07 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 15k+
P: 16,027
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.
Nov 12 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.