Wrox Programmer Forums
BOOK: Professional Ajax ISBN: 978-0-471-77778-6
This is the forum to discuss the Wrox book Professional Ajax by Nicholas C. Zakas, Jeremy McPeak, Joe Fawcett; ISBN: 9780471777786
Important: For the new 2nd edition of this book, please post here instead: [url="http://p2p.wrox.com/forum.asp?FORUM_ID=307"]http://p2p.wrox.com/forum.asp?FORUM_ID=307[/url]
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Ajax ISBN: 978-0-471-77778-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 6th, 2006, 05:22 PM
Registered User
Join Date: Jul 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Jman82 Send a message via AIM to Jman82 Send a message via MSN to Jman82 Send a message via Yahoo to Jman82
Default IE Memory Leak

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


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

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")
      set rs = nothing
   end function

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="javascript">
function createRequestObject() 
    var req;
        // 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

/*    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()
/************  END LIVE DATA ******************************/    



<body onLoad="dashboard();">

      <td align="right" id="products" style="padding-right:5px; "></td>

      <td align="right" id="revisions" style="padding-right:5px; "></td>

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?


Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory leak in a loop neilsands Java Basics 4 March 17th, 2010 05:59 AM
Looking for Memory Leak Advice Bill_Thompson Visual C++ 0 October 16th, 2007 05:42 PM
Memory Leak in ADO Seeja Pro VB Databases 1 December 27th, 2004 07:28 PM
Think I have a memory leak, need advice grantmeans Classic ASP Databases 1 March 12th, 2004 03:45 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.