Im getting a memory leak with my live data. I'm using it to track a few different variables and cant seem to resolve the problem. The leak is only present in IE so I think it has something to do with the ActiveXObject("Microsoft.XMLHTTP")
Im using
VB for my DataAccess
liveData.asp
Code:
<%
Dim cnn
Set cnn = Server.CreateObject("ADODB.Connection")
cnn.Open "Provider=SQLOLEDB;Data Source=*********; Initial Catalog=*************; Integrated Security=SSPI;"
select case request("act")
case "revisions"
response.write(rCount("Revisions", "")) 'LastEditDate > '/25/2006'
case "products"
response.write(rCount("Products", ""))
end select
cnn.close
set cnn = nothing
Function rCount(tblName, strCond)
dim cmd, rs
set cmd = server.CreateObject("ADODB.command")
set rs = server.CreateObject("ADODB.recordset")
dim strWhere
if strCond <> "" then
strWhere = " WHERE " & strCond
end if
with cmd
.activeConnection = cnn
.commandText = "SELECT Count(*) as ItemCount FROM " & tblName & strWhere
.commandType = adCmdText
set rs = .execute
end with
set strWhere = nothing
set tblName = nothing
set strCond = nothing
set cmd = nothing
rCount = rs("ItemCount")
rs.close
set rs = nothing
end function
%>
debug.html
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="javascript">
function createRequestObject()
{
var req;
if(window.XMLHttpRequest){
// Firefox, Safari, Opera...
req = new XMLHttpRequest();
} else if(window.ActiveXObject) {
// Internet Explorer 5+
req = new ActiveXObject("Microsoft.XMLHTTP");
} else {
// There is an error creating the object,
// just as an old browser is being used.
alert('There was a problem creating the XMLHttpRequest object');
}
return req;
}
/*LIVE DATA ******************************/
/* sendLiveRequest
* Parameters (4):
* act - the action you want to perform in liveData.asp
* divtag - the division tag you want to show the data in
* func - the name of the function you want to run ever rtime milliseconds calling sendRequest
* rtime - how often you want the function to be recalled
* Description:
* Display information at the element with id = divtag and updates this data every rtime milisecods.
* The page does not refresh just the contents of the element with the ID change.
*/
function sendLiveRequest(act, divtag, func, rtime) {
var url = 'liveData.asp?act=' + act + "&rdm=" + Math.random(); //create the url to open math.random keeps the page from loaded cached data
var httpL = createRequestObject(); //create the XMLHttpRequest object
httpL.open('get', url);
httpL.onreadystatechange = function() { handleLiveResponse(httpL, divtag, func, rtime); }; //creates the handler that calls the function evertime the state changes of the XMLHttpRequest object
httpL.send(null);
}
/* handleLiveRequest
* Parameters (4):
* httpL - an XMLHttpRequest object
* divtag - the division tag you want to show the data in
* func - the name of the function you want to run ever rtime milliseconds calling sendRequest
* rtime - how often you want the function to be recalled
* Description:
* function runs every time httpL changes states when status and ready state are complete then
* update innerHTML of divtag and setTimeout before recalling the function
*/
function handleLiveResponse(httpL, divtag, func, rtime )
{
if(httpL.readyState == 4 && httpL.status == 200) //check to see if the request page is done
{
var response = httpL.responseText; // Text returned VB script
if(response) // if response is blank dont do anything
{
document.getElementById(divtag).innerHTML = response; //update information in divtag
setTimeout(eval(func),rtime); //recall func in rtime miliseconds
}
}
}
/* The Folowing function are the function defined to be called for the live data */
function liveRevisionCount() {
sendLiveRequest('revisions', 'revisions', 'liveRevisionCount', 1000);
}
function liveProductCount(){
sendLiveRequest('products', 'products', 'liveProductCount', 5000);
}
/* end live data functions */
/* dashboard
* Description:
* Function called on load to start monitoring the live data
* It in turn calls the live data functions
*/
function dashboard()
{
liveProductCount();
liveRevisionCount();
}
/************ END LIVE DATA ******************************/
</script>
</head>
<body onLoad="dashboard();">
<table>
<tr>
<td align="right" id="products" style="padding-right:5px; "></td>
<td>Products</td>
</tr>
<tr>
<td align="right" id="revisions" style="padding-right:5px; "></td>
<td>Revisions</td>
</tr>
</table>
</body>
</html>
I did some testing and if you comment out the response.write(rCount("Revisions", "")) and the response.write(rCount("Products", "")) line and replace one with response.write("test") the leak still exists.
but if there is no response at all there is no leak.
Any Ideas?
Thanks