0

I've got a working piece of code that contacts nominatim for geocoding. This is done via a cross domain request. For every request I create a unique callback function. I've noticed all these old request 'piling up' in the DOM inspector. Since I'm changing the site to a more App-like behavior (and users thus staying on the same page) this could become a problem.

How do I clear these old requests and variables? Just in order to clear the DOM and prevent this obvious waste of memory.

  $.ajax({
        url: 'http://nominatim.openstreetmap.org/search',
        type: 'GET',
        dataType: 'jsonp',
        jsonp: 'false',
        jsonpCallback: 'json_callback' + myGeocoder.requestIndex,
        data: {
            format: 'json',
            q: request.term,
            addressdetails: 1,
            limit: 10,
            json_callback: 'json_callback' + myGeocoder.requestIndex
        },
        beforeSend: function(x) { 
            if (x && x.overrideMimeType) { 
                x.overrideMimeType("application/json;charset=UTF-8"); 
            } 
        },
        success: processResult
    });
    myGeocoder.requestIndex++;

and in the Firebug DOM inspetor, after a few uses of the function:

 json_callback0 undefined
 json_callback1 undefined
 json_callback2 undefined
 json_callback3 undefined
 json_callback4 undefined
 json_callback5 undefined
 json_callback6 undefined
 json_callback7 undefined
 json_callback8 undefined
 json_callback9 undefined

and so on...

Jeroen
  • 1,638
  • 3
  • 23
  • 48
  • Would have to be within JQuery, and does not look like it is happening any time soon: https://github.com/jquery/jquery/pull/744. Maybe have a look at this question: http://stackoverflow.com/questions/9570768/pass-additional-parameter-to-a-jsonp-callback – mccannf Nov 21 '12 at 17:27
  • hey, thx. I've looked at your links and it seems that it did got a commit though: https://github.com/jquery/jquery/commit/8ebb2f4793d2c464888b5f0dba97fb5c9d0c9541 I am using the 1.7.2 version, but after that there's somewhat of a rewrite of the /src/ajax/jsonp.js . Perhaps I should try to use the 1.8.3 jQuery and also use the internal callback generation. I'll try tomorrow – Jeroen Nov 21 '12 at 20:08

0 Answers0