Ajax Memory Leak

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • venkikam
    New Member
    • Aug 2007
    • 2

    Ajax Memory Leak

    Hi All,

    I have a web application that calls an AjaxMethod every 1min based on a javascript timer. It appears that every time I call this ajax method, IE uses more memory.

    My function goes like..

    [CODE=javascript]function ajaxFunction() {

    var xmlHttp;
    xmlHttp = new XMLHttpRequest( );
    xmlHttp.open("G ET","./currentActivity Report.do?actio n=RefreshCurren tActivity&"+par ameter,true);
    xmlHttp.onready statechange=fun ction() {

    if(xmlHttp.read yState==4) {

    var myspan = document.getEle mentById('myspa n');
    var table = document.getEle mentById("Table ");
    myspan.removeCh ild(table);
    table = null;
    var newspan = document.create Element('span') ;
    newspan.setAttr ibute("id","Tab le");
    myspan.appendCh ild(newspan);
    document.getEle mentById("Table ").innerHTML=xm lHttp.responseT ext;
    xmlHttp.onready statechange=fun ction() {};
    xmlHttp.abort() ;
    }
    }

    xmlHttp.send("" );
    }[/CODE]

    If any knows about the problem please let me know..
    Last edited by acoder; Sep 7 '07, 07:50 AM. Reason: Added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Please use code tags when posting code.

    On line 23, change [CODE=javascript]xmlHttp.send("" );[/CODE] to [CODE=javascript]xmlHttp.send(nu ll);[/CODE]

    Comment

    • baudSmoke
      New Member
      • Nov 2007
      • 1

      #3
      The innerHTML is over writting html and not releasing it from memory. You will have to look for alternatives to innerHTML.

      A JavaScript framework such as the MochiKit is free and can handle your ajax requests for you and resolve all browser incompatabilies .

      I have not done this myself yet; so I cannot help you any further.

      Comment

      • mrkrunal
        New Member
        • Mar 2008
        • 1

        #4
        Originally posted by venkikam
        Hi All,

        I have a web application that calls an AjaxMethod every 1min based on a javascript timer. It appears that every time I call this ajax method, IE uses more memory.

        My function goes like..
        [CODE=javascript]function ajaxFunction() {

        var xmlHttp;
        xmlHttp = new XMLHttpRequest( );
        xmlHttp.open("G ET","./currentActivity Report.do?actio n=RefreshCurren tActivity&"+par ameter,true);
        xmlHttp.onready statechange=fun ction() {

        if(xmlHttp.read yState==4) {

        var myspan = document.getEle mentById('myspa n');
        var table = document.getEle mentById("Table ");
        myspan.removeCh ild(table);
        table = null;
        var newspan = document.create Element('span') ;
        newspan.setAttr ibute("id","Tab le");
        myspan.appendCh ild(newspan);

        xmlHttp.onready statechange=fun ction() {document.getEl ementById("Tabl e").innerHTML=x mlHttp.response Text;
        };
        xmlHttp.abort() ;
        }
        }

        xmlHttp.send("" );
        }[/CODE]

        check ur code now............ .......and even if u r getting an error/problem then pur ur table in the function of xmlhttp.readyst atechange()

        try..it and reply me if my tips would become helpful to u.............

        Comment

        Working...