Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Potential Memory Leak when with Ajax

    Hi all.
    I'm using JavaScript to call a server side service provided by an IBMBPM Tool (Lombardi teamworks), to retrieve an XML object.

    I've stripped it down to the bare essentials below.
    When I click on the button, it runs the call 5000 times.
    Any browser grabs a whole load of memory and never lets go of it. What Am I doing wrong here?

    The code is below.

    Code:
    <script>
    
        function makeRequest(url, params, callBack) {
            var http_request = false;
            if (window.XMLHttpRequest) { // Mozilla, Safari, ...
                http_request = new XMLHttpRequest();
                if (http_request.overrideMimeType) {
                    http_request.overrideMimeType('text/xml');
                    // See note below about this line
                }
            } else if (window.ActiveXObject) { // IE
                try {
                    http_request = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                    try {
                        http_request = new ActiveXObject("Microsoft.XMLHTTP");
                    } catch (e) {}
                }
            }
            if (!http_request) {
                alert('Giving up :( Cannot create an XMLHTTP instance');
                return false;
            }
            http_request.onreadystatechange = function() {
                    if (http_request.readyState == 4) {
                if (http_request.status == 200) {
                    callBack(http_request.responseText);
                } else {
                    alert('There was a problem with the request.');
                }
            }};
            http_request.open('GET', url, true);
            http_request.send(params);
        }
    
    tw.coach.callServiceRegus = function(service, params, callBack, snapshot) {
     if(snapshot == "" || snapshot == null) {
         // coachSnapshotContext is injected via the CoachDesigner.xsl
         snapshot = coachSnapshotContext;
     }
     var url = "/portal/jsp/callService.do?serviceName=" + service + "&snapshotId=" + snapshot;
     makeRequest(url, params, callBack);
    };
    
    
    function getTickets(){
        var data;
        var inputVar = '<input><variable name="inputVar">dion.jones</variable>'
        inputVar += '<variable name="sortOrder">t.Priority, t.CreateDate</variable>'
        inputVar += '<variable name="displayType">UserLandingPage</variable>'
        inputVar += '</input>';
        tw.coach.callServiceRegus('SORGetUserTicketsXML', 
          inputVar,
          function(data){
          }
        );
    }
    
    
    function explode(){
    for (var i = 0 ; i < 5001 ; i++) {
    getTickets();
    }
    alert("done");
    }
    </script>
    
    
    
    
    This button is in the HTML on the page.
    
    <!-- Refrech Button -->
    
    <input type="button" onclick="explode();" value="clickerty-Click!" />

  • #2
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I apologise for the Thread title also - my brain is obviously malfunctioning this morning and I can't find a way to edit it.

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    972
    Thanks
    19
    Thanked 212 Times in 210 Posts
    Making 5000 XMLHttprequest objects
    will never be a good idea.You should
    make 4 at the start of your code and
    reuse them, it is not useful to have
    more that 4 making a requst of the
    same URL at the same time as most
    browser are limited to 4 or less connections
    to the same URL at the same time.

  • #4
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i see.
    I was just using the 5000 calls to test and magnify the memory leak issue.

    Are you saying I should just call 4 and then loop using these?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •