Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery JSONP polling memory leaks

I need to perform jsonp long polling in highly dynamic web application, however I'm experiencing massive memory leaks. Initially I've used Socket.IO and the jsonp transport with the same results and then setup a JQuery test page to see if the problem was localized only in the socket.io lib. I've found to my surprise that also doing jsonp polling from JQuery lead to the same results: in IE9 the memory increases very fast(less than 10 min ) from around 80-90 MB to more than 1.8 GB :(.

He're is the test code for the client side:

<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">        
    <script type="text/javascript">
        $(document).ready( function() {
            var doPoll = function() {
                $.ajax({
                    type: 'GET',
                    url: "http://<server-url>/jquery-jsonp/server.php",
                    cache: false,
                    async: true,
                    crossDomain: true,
                    dataType: "jsonp",
                    success: function (data, status) {
                        console.log("Received response"+data);
                        doPoll();
                    },
                    error: function (xhr, textStatus, errorThrown) {
                        // access denied
                    }
                });
            }

            doPoll();     
        });
    </script>
</head>

And here is the dummy server response:

<?php echo $_GET['callback']."(".json_encode(array("status"=>"success")).")";

As you can see nothing special here. Any thoughts on what is causing this and possible work-arounds ?

The request need to be performed cross origin and we must support IE8/9. Thank you very much.

like image 300
user1835551 Avatar asked Aug 04 '26 12:08

user1835551


1 Answers

Try calling doPoll() at an interval of a few seconds, like this:

success: function (data, status) {
    console.log("Received response"+data);
    setTimeout(doPoll, 10000); // 10 second wait before next request sent
},
like image 108
Rory McCrossan Avatar answered Aug 07 '26 00:08

Rory McCrossan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!