I'm aware of the circular reference memory leak problem with IE/closures.
I'm not sure exactly how to resolve it in this situation. Also, Firefox
appears to grow its memory size with the same code. So I'm wondering if I'm
missing something?
My test code is as follows:
function myObj() {
var req = new Object();
req.temp = 0;
if (window.XMLHttp Request) { req.xmlHttpRequ est = new XMLHttpRequest( ); }
else if (window.ActiveX Object) { req.xmlHttpRequ est = new
ActiveXObject(" Msxml2.XMLHTTP" ); }
req.xmlHttpRequ est.onreadystat echange =
function() {
if (req.readyState ==4) {
req.temp = req.xmlHttpRequ est.responseTex t;
}
};
req.xmlHttpRequ est.open("GET", "/",true);
req.xmlHttpRequ est.send(null);
return req;
}
// Create a whole bunch of these objects to check for memory leak
for (var i=0; i<1000; i++) {
var x = new myObj();
}
What is the best way to avoid memory leaking in this example?
--
Matt Kruse
http://www.JavascriptToolbox.com