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...