I have a google map on my web page, and uses geoxml3 to parse the layers (with many placemarks).
There is a timer that will trigger a jquery every 10 seconds to pull the new .kml file. However I want to remove the old layer, before parsing the new layer.
Question: What is the right way of removing/destroying?
I know there is a geoXml.hideDocument();
, but that only hides the layer, it does not remove/destroy the layer right? (below is the hideDocument() implementation)
refreshMap() - hide previous layer and show new layer
$.ajax({
url: url,
dataType: 'json',
type: 'get',
contentType: 'application/x-www-form-urlencoded',
data: "",
success: function (data, textStatus, jQxhr) {
if (data['success'] == 1) {
if (geoXml)
geoXml.hideDocument();
var src = data['kml'];
geoXml = new geoXML3.parser({
map: map,
suppressInfoWindows: false,
singleInfoWindow: true,
infoWindow: infowindow,
zoom : false
});
geoXml.parse(src);
geoXml.showDocument();
}
},
error: function (jqXhr, textStatus, errorThrown) {
console.log(errorThrown);
}
});
Even though this works, but my worry is that if it keeps pulling data every 10 seconds, if the page is opened for 1 hour, will it cause any lag? Reason being that the overlays are not actually destroyed/removed, they are still on memory, just that we lose the reference to it (because now reference point to the new layer).
Update
I found some information online, seems like I don't have to worry about this implementation.
"Since Javascript is garbage collected, you don't need to delete objects themselves - they will be removed when there is no way to refer to them anymore."
I have a test case that effectively does this:
filename="http://www.geocodezip.com/dynamicmarkerkml.php";
geoXml.parse(filename);
setInterval("geoXml.hideDocument();geoXml.parse(filename)", 5000);
Doesn't leak memory that I can see and I have had it running for days (at one point, not recently).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.