I have a Yahoo map with lots of markers (~500). The map performs well enough until I close the page, at which point it pauses (in Firefox) and brings up a "Stop running this script?" dialog (in IE7). If given long enough the script does complete its work.
Is there anything I can do to reduce this delay?
This stripped down code exhibits the problem:
<script type="text/javascript">
var map = new YMap(document.getElementById('map'));
map.drawZoomAndCenter("Algeria", 17);
for (var i = 0; i < 500; i += 1) {
var geoPoint = new YGeoPoint((Math.random()-0.5)*180.0, (Math.random()-0.5)*360.0);
var marker = new YMarker(geoPoint);
map.addOverlay(marker);
}
</script>
I'm aware of some memory leaks with the event handlers if you're dynamically adding and removing markers, but these are static (though the problem may be related). Oh, and I know this many markers on a map may not be the best way to convey the data, but that's not the answer I'm looking for ;)
Edit: Following a suggestion below I've tried:
window.onbeforeunload = function() {
map.removeMarkersAll();
}
and
window.onbeforeunload = function() {
mapElement = document.getElementById('map');
mapElement.parentNode.removeChild(mapElement);
}
but neither worked :(