I have a Google map running with scripts (jQuery) and consuming markers and polygons from a bunch of RESTful web services deployed in the same server. All seems to work fine, but after a few minutes of running a simulation (simply redrawing the overlays after n seconds with the setInterval
function) my computer shuts down! I am not even getting the Blue Screen of Death (BSoD), the computer just goes off!
I realised it has something to do with memory (removing other overlays code, takes longer to go off). I think I did release memory as you can see in this snippet, but I am not certain. What am I missing?
function deleteOverlay(overl) {
if (overl)
{
for (i in overl)
{
overl[i].setMap(null);
}
overl.length = 0;
overl = [];
}
}
function populate(map) {
var infowindow = new google.maps.InfoWindow({content: ''});
jQuery.get("/MyServiceRESTful/resources/passengers/", {}, function (data) {
deleteOverlay(passengersArray);
jQuery(data).find("passenger").each(function () {
var marker = jQuery(this);
var idtxt = marker.attr("id");
var sntxt = marker.attr("snippet");
var location = marker.attr("lat")+', '+marker.attr("lng");
var latlng = new google.maps.LatLng(parseFloat(marker.attr("lat")),parseFloat(marker.attr("lng")));
var marker = new google.maps.Marker({
position : latlng,
map : map,
title : marker.attr("id") + " [" + marker.attr("snippet") + "]",
animation : google.maps.Animation.NONE,
icon : passengermarker
});
var contentString = 'Hi';
google.maps.event.addListener(marker, 'mouseover', function () {
infowindow.content = contentString;
infowindow.open(map, marker);
});
passengersArray.push(marker);
});
});
//More similar calls
}
After the discussion in the chat above and looking at your code, it looks like you are making no of calls to your web server and this is causing your server to meltdown.
I would suggest you make these calls to the server dynamic, that is, make it on request instead of loading it up front for whatever reason.. If, as a single person, you are ending up killing your server, I can't imagine what will happen when your site goes live.. Ideally make it as on demand as possible attach events to your map objects and fire them only when necessary.
I hope this is a valid approach you could take or please update the question to show us more code and what you are trying to achieve..